Sariali
13 years agoContributor
Casting OleObject
Hello again!
Is it possible to cast OleObjects?
Example:
Delphi:
Unit1:
TForm1 = class
function GetValue : integer;
end;
Unit2:
TForm2 = class
function GetValue : integer; // same functionname
end;
TestComplete / DelphiScript:
function GetValue(FormName : string) : integer;
begin
Result := -1;
if FormName = "Form1" then
Result := Aliases.Sys.MyProg.Form1.GetValue
else if FormName = "Form2" then
Result := Aliases.Sys.MyProg.Form2.GetValue
// ... and so on
end;
procedure Test;
var Value;
begin
Value := GetValue('Form1'); // the Text of Object "Form1"
end;
It would be pretty nice to have this to avoid writing long case-cascades:
function GetValue(Form : OleObject) : integer;
begin
Result := Form.GetValue; // The Problem is that the OleObject "Form" don't know about the function "GetValue"
// How can one cast "Form" so that the function "Form1.GetValue" is accessible?
end;
procedure Test;
var Value;
begin
Value := GetValue(Form1); // the Object "Form1"
end;
thank you for your help!
Necip Sariali