23-05-2023, Saat: 02:49
Merhaba,
Asagidaki sekilde bir sayfa olusturdum.
Asagidaki butonlardan herhangi birine tiklandigi zaman, id'yi delphi icinden okumak istiyorum.
Su anda bu islem icin asagidaki MyMessages procedure'ni kullaniyorum. Fakat her zaman saglikli olarak calismiyor.
Saglikli olarak calismiyor derken; butonda bastigim yere bagli olarak id'yi döndüruyor ya da döndürmüyor
Bunun icin en saglikli yontem nedir? (Delphi 7 kullaniyorum.)
Tesekkur ederim.
procedure TfrmTest.MyMessages(var Msg: TMsg;
var Handled: Boolean);
var
i,
X,
Y: Integer;
document,
E: OleVariant;
begin
if (Msg.message = WM_LBUTTONDOWN) and IsDialogMessage(WebBrowser1.Handle, Msg) then
begin
X := LOWORD(Msg.lParam);
Y := HIWORD(Msg.lParam);
document := WebBrowser1.Document;
E := document.elementFromPoint(X, Y);
if (E.ClassName = 'button') and (E.Id <> '')then
begin
ShowMessage(E.Id);
end;
Handled := False;
Exit;
end;
end;
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<style> html, body { margin: 0; height: 100;}
.button {
border: none;
height: 60px;
width: 116px;
padding: 2px 2px;
padding-top: 1px;
padding-bottom: 0px;
text-align: left;
text-decoration: none;
display: inline-block;
vertical-align: top;
display: table-cell;
font-size: 12px;
margin: 8px 8px;
cursor: pointer;
white-space: normal;
word-wrap: break-word;
}
</style>
</head>
<body style="background-color:Silver;">
<table>
<tr>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="77p"; ><b>Ilk Urun deneme yanilma icin biraz uzun text yazmayi denedim bu urunde.</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="79p"; ><b>Ikinci Urun0</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="81p"; ><b>Ucuncu Urun</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="83p"; ><b>Dorduncu Urun</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="85p"; ><b>Besinci Urun</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="87p"; ><b>Son Urun</b></td>
</tr>
</table>
</body>
</html>
Asagidaki sekilde bir sayfa olusturdum.
Asagidaki butonlardan herhangi birine tiklandigi zaman, id'yi delphi icinden okumak istiyorum.
Su anda bu islem icin asagidaki MyMessages procedure'ni kullaniyorum. Fakat her zaman saglikli olarak calismiyor.
Saglikli olarak calismiyor derken; butonda bastigim yere bagli olarak id'yi döndüruyor ya da döndürmüyor
Bunun icin en saglikli yontem nedir? (Delphi 7 kullaniyorum.)
Tesekkur ederim.
procedure TfrmTest.MyMessages(var Msg: TMsg;
var Handled: Boolean);
var
i,
X,
Y: Integer;
document,
E: OleVariant;
begin
if (Msg.message = WM_LBUTTONDOWN) and IsDialogMessage(WebBrowser1.Handle, Msg) then
begin
X := LOWORD(Msg.lParam);
Y := HIWORD(Msg.lParam);
document := WebBrowser1.Document;
E := document.elementFromPoint(X, Y);
if (E.ClassName = 'button') and (E.Id <> '')then
begin
ShowMessage(E.Id);
end;
Handled := False;
Exit;
end;
end;
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<style> html, body { margin: 0; height: 100;}
.button {
border: none;
height: 60px;
width: 116px;
padding: 2px 2px;
padding-top: 1px;
padding-bottom: 0px;
text-align: left;
text-decoration: none;
display: inline-block;
vertical-align: top;
display: table-cell;
font-size: 12px;
margin: 8px 8px;
cursor: pointer;
white-space: normal;
word-wrap: break-word;
}
</style>
</head>
<body style="background-color:Silver;">
<table>
<tr>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="77p"; ><b>Ilk Urun deneme yanilma icin biraz uzun text yazmayi denedim bu urunde.</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="79p"; ><b>Ikinci Urun0</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="81p"; ><b>Ucuncu Urun</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="83p"; ><b>Dorduncu Urun</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="85p"; ><b>Besinci Urun</b></td>
<td class="button"; style="font-size: 14px; background-color: White; color:Black;" id="87p"; ><b>Son Urun</b></td>
</tr>
</table>
</body>
</html>

