ใน Virtual Treeview ของ Mike Lischke มีการเพิ่มโค้ดวิธีแก้ปัญหาเพื่อแก้ไขข้อบกพร่องเมื่อใช้ < strong>TWebBrowser ควบคุมในรูปแบบเดียวกัน
ปัญหาคือหากผู้ใช้พยายามโต้ตอบกับ TOleControl (ซึ่ง TWebBrowser ลงมา) การคลิกเมาส์ครั้งแรกจะถูกกิน พวกเขาจะต้องคลิกอีกครั้งเพื่อให้มีสมาธิในการควบคุม จากนั้น พวกเขาสามารถโต้ตอบกับการควบคุมได้
เขามีความคิดเห็นที่จะอธิบาย:
ทุกการควบคุมที่ได้รับจาก
TOleControl
อาจมีปัญหาในการโฟกัสเพื่อหลีกเลี่ยงการรวมหน่วย OleCtrls (ซึ่งจะรวมถึง ตัวแปร) ซึ่งจะอนุญาตให้ทดสอบคลาส
TOleControl
อินเทอร์เฟซIOleClientSite
จะใช้สำหรับ ทดสอบซึ่งได้รับการสนับสนุนโดยTOleControl
และเป็นตัวบ่งชี้ที่ดี
จากตัวอย่างเต็ม:
procedure TBaseVirtualTree.WMKillFocus(var Msg: TWMKillFocus);
var
Form: TCustomForm;
Control: TWinControl;
Pos: TSmallPoint;
Unknown: IUnknown;
begin
inherited;
[snip]
{
Workaround for wrapped non-VCL controls (like TWebBrowser),
which do not use VCL mechanisms and
leave the ActiveControl property in the wrong state,
which causes trouble when the control is refocused.
}
Form := GetParentForm(Self);
if Assigned(Form) and (Form.ActiveControl = Self) then
begin
Cardinal(Pos) := GetMessagePos;
Control := FindVCLWindow(SmallPointToPoint(Pos));
{
Every control derived from TOleControl has potentially
the focus problem. In order to avoid including
the OleCtrls unit (which will, among others, include Variants),
which would allow to test for the TOleControl
class, the IOleClientSite interface is used for the test,
which is supported by TOleControl and a good indicator.
}
if Assigned(Control) and Control.GetInterface(IOleClientSite, Unknown) then
Form.ActiveControl := nil;
// For other classes the active control should not be modified. Otherwise you need two clicks to select it.
end;
end;
ปัญหาคือวิธีแก้ปัญหาไม่ทำงานสำหรับฉันอีกต่อไป และบอกตามตรงว่าฉันไม่รู้ว่าจริงๆ แล้วปัญหาคืออะไร และวิธีแก้ปัญหาของเขาแก้ไขได้อย่างไร
มีใครบ้างที่รู้ว่าความคิดเห็นของเขาเข้าใจในสิ่งที่เขาพูดถึง สามารถอธิบายได้ว่าปัญหาคืออะไร และสิ่งที่เขาทำอยู่จะแก้ไขได้อย่างไร
วิธีแก้ปัญหาสำหรับการควบคุมที่ไม่ใช่ VCL แบบห่อ (เช่น TWebBrowser) ซึ่งไม่ได้ใช้กลไก VCL และปล่อยให้คุณสมบัติ ActiveControl อยู่ในสถานะที่ไม่ถูกต้อง ซึ่งทำให้เกิดปัญหาเมื่อมีการปรับโฟกัสการควบคุม การควบคุมทุกอย่างที่ได้รับจาก TOleControl อาจมีปัญหาในการโฟกัส
รหัสไปถึงที่ตั้งใจไว้
Form.ActiveControl := nil;
คำสั่ง แต่มันก็ไม่ได้ทำเคล็ดลับ
ฉันจะแก้ไข แต่ฉันไม่รู้ว่าเขาพบมันได้อย่างไร หรือเหตุใด TOleControl จึงไม่ ใช้กลไก VCL และปล่อยให้คุณสมบัติ ActiveControl อยู่ในสถานะที่ไม่ถูกต้อง< /em>.
โบนัสการอ่าน
เดิมทีฉันถามคำถามนี้ ใน borland.public.delphi.nativeapi.win32
newsgroup ในปี 2551
บั๊ม 20110515 (12 เดือนต่อมา)
Bump 20150401 (7 ปีต่อมา): ยังใช้งานไม่ได้ใน XE6
บั๊ม 20210309 (11 ปีต่อมา)