
Aşağıdaki kodlar çalışıyormuş normalde ama ben becermedim.
Soru : Ne yapmaya çalışıyorsun ?
Cevap : Amacım dosya yükleme yapmak için dosya yolunu açtırmaya çalışıyorum. Ama bir türlü beceremedim. kullanıcı herhangi şekilde müdahale etmeyecek. Amaç tam olarak program gözat butonuna tıklayacak resim yolunuyazacak ve ok basacak.
Şimdiden yardımcı olan herkese tşkler
ttt.html
Kod: Tümünü seç
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form action="">
<INPUT TYPE="file" NAME="imagefile" SIZE="27">
</form>
</body>
</html>
Kod: Tümünü seç
uses ...mshtml, PushKey, ActiveX;
procedure TForm1.FormShow(Sender: TObject);
begin
Button1.Enabled := False;
Webbrowser1.Navigate('c:\ttt.html');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
Document: IHTMLDocument2;
Element: IHTMLInputFileElement;
begin
Document := Webbrowser1.Document as IHTMLDocument2;
if Assigned(Document) then
begin
// this is the first key to getting this done
// You have to set focus to the WebBrowser
with WebBrowser1.Application as IOleobject do
DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle,
GetClientRect);
Element := Document.all.item('imagefile', EmptyParam) as
IHTMLInputFileElement;
if assigned(Element) then // choosedialog here?
begin
if not Element.disabled then
begin
// this is the second key to getting this done.
// you have to tab into the control
for i := 0 to (Element as IHTMLControlElement).tabIndex do
PressKey(VK_TAB, 0);
// And this is the last key, change to the filename
// you want...
PushKeys('c:\tttt.html');
end;
end;
end;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
Button1.Enabled := True;
end;