Kristian
asked on
Problems with 'IS' in a DLL.
I have a DLL and in it i have a standard function that is given some data and a label or panel ( TObject ) and then is meant to display a name in the Label and color it, show extra information ETC.
Code :
Procedure DisplayPersonName(Profile : TDllProfile; Query : TSQLSelect;DisplayLabel : TObject);Register;
var
CaptionText : string;
Colour : TColor;
FontColour : TColor;
begin
Dllprofile := profile;
if not assigned(database) then
RawConnect(Dllprofile);
{All of my setting of the Caption + colors goes Here}
if not assigned(DisplayLabel) then exit;
if (DisplayLabel is TPanel)then
begin
(DisplayLabel as TPanel).Color := Colour;
(DisplayLabel as TPanel).font.Color := FontColour;
(DisplayLabel as TPanel).Caption := CaptionText;
(DisplayLabel as TPanel).Hint := CaptionText;
(DisplayLabel as TPanel).ShowHint := True;
end;
else
try
(DisplayLabel as TLabel).Color := Colour;
(DisplayLabel as TLabel).font.Color := FontColour;
(DisplayLabel as TLabel).Caption := CaptionText;
(DisplayLabel as TLabel).Hint := CaptionText;
(DisplayLabel as TLabel).ShowHint := True;
except
AppMessage('DisplayPersonN ame --> Unknown display type !');
end;
end;
Simple !!!!!!
but sometimes the code does not correctly work out what the DisplayLabel IS !!
I am passing directly the object itself, IE Form1.MyPanel
but sometimes it works, im a bit confused.
i have stepped it through many times now and i dont understand ahy it thinks a label or panel is not a label or a panel !?!?!?
Help
Cheers with usual anticipation
Kristian
Code :
Procedure DisplayPersonName(Profile : TDllProfile; Query : TSQLSelect;DisplayLabel : TObject);Register;
var
CaptionText : string;
Colour : TColor;
FontColour : TColor;
begin
Dllprofile := profile;
if not assigned(database) then
RawConnect(Dllprofile);
{All of my setting of the Caption + colors goes Here}
if not assigned(DisplayLabel) then exit;
if (DisplayLabel is TPanel)then
begin
(DisplayLabel as TPanel).Color := Colour;
(DisplayLabel as TPanel).font.Color := FontColour;
(DisplayLabel as TPanel).Caption := CaptionText;
(DisplayLabel as TPanel).Hint := CaptionText;
(DisplayLabel as TPanel).ShowHint := True;
end;
else
try
(DisplayLabel as TLabel).Color := Colour;
(DisplayLabel as TLabel).font.Color := FontColour;
(DisplayLabel as TLabel).Caption := CaptionText;
(DisplayLabel as TLabel).Hint := CaptionText;
(DisplayLabel as TLabel).ShowHint := True;
except
AppMessage('DisplayPersonN
end;
end;
Simple !!!!!!
but sometimes the code does not correctly work out what the DisplayLabel IS !!
I am passing directly the object itself, IE Form1.MyPanel
but sometimes it works, im a bit confused.
i have stepped it through many times now and i dont understand ahy it thinks a label or panel is not a label or a panel !?!?!?
Help
Cheers with usual anticipation
Kristian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perhaps try to use a common ancestor of TPanel and TLabel
like TControl(DisplayLabel).Col or := Color;
or assume by default that it's panel, then if there's an
error, assume it's a label:
try
(DisplayLabel as TPanel).Color := Colour;
(DisplayLabel as TPanel).font.Color := FontColour;
(DisplayLabel as TPanel).Caption := CaptionText;
(DisplayLabel as TPanel).Hint := CaptionText;
(DisplayLabel as TPanel).ShowHint := True;
except
try
(DisplayLabel as TLabel).Color := Colour;
(DisplayLabel as TLabel).font.Color := FontColour;
(DisplayLabel as TLabel).Caption := CaptionText;
(DisplayLabel as TLabel).Hint := CaptionText;
(DisplayLabel as TLabel).ShowHint := True;
except
end;
end;
like TControl(DisplayLabel).Col
or assume by default that it's panel, then if there's an
error, assume it's a label:
try
(DisplayLabel as TPanel).Color := Colour;
(DisplayLabel as TPanel).font.Color := FontColour;
(DisplayLabel as TPanel).Caption := CaptionText;
(DisplayLabel as TPanel).Hint := CaptionText;
(DisplayLabel as TPanel).ShowHint := True;
except
try
(DisplayLabel as TLabel).Color := Colour;
(DisplayLabel as TLabel).font.Color := FontColour;
(DisplayLabel as TLabel).Caption := CaptionText;
(DisplayLabel as TLabel).Hint := CaptionText;
(DisplayLabel as TLabel).ShowHint := True;
except
end;
end;
Instead of
(DisplayLabel as TPanel) and (DisplayLabel as TLabel)
use
Tpanel(DisplayLabel) and Tlabel(DisplayLabel)
(DisplayLabel as TPanel) and (DisplayLabel as TLabel)
use
Tpanel(DisplayLabel) and Tlabel(DisplayLabel)
ASKER
this seems to have done it :
if DisplayLabel.ClassName = 'TPanel' then
begin
TPanel(DisplayLabel).Color := Colour;
TPanel(DisplayLabel).font. Color := FontColour;
TPanel(DisplayLabel).Capti on := CaptionText;
TPanel(DisplayLabel).Hint := CaptionText;
TPanel(DisplayLabel).ShowH int := True;
end
else
try
TLabel(DisplayLabel).Color := Colour;
TLabel(DisplayLabel).font. Color := FontColour;
TLabel(DisplayLabel).Capti on := CaptionText;
TLabel(DisplayLabel).Hint := CaptionText;
TLabel(DisplayLabel).ShowH int := True;
except
AppMessage('DisplayPersonN ame --> Unknown display type !');
end;
and i am also compiling with runtime packages ( well i was befor anyway ) but the combination works...
I have noticed that since using delphi 5 and a lot more Dll's and packages things are a little more delicate and i find myself working around a lot of problems like this ! am i the only one ?
Im a bit split on who answered the question it was Madshi, even though sesa did have an influence. I will post an extra 25 for sesa in a new question ETC.
Cheers guys.
Kristian
oh and ps sorry it took me a while to get back but my packages fell apart half way through and i ended up having to remove them by deleting the registry settings just to remove the package so i could recompile it again so i could install it, as every time i tried to compile or uninstall it it would crash delphi..... like i said is it me or is delphi 5 a bit flakey with the use of packages ??
if DisplayLabel.ClassName = 'TPanel' then
begin
TPanel(DisplayLabel).Color
TPanel(DisplayLabel).font.
TPanel(DisplayLabel).Capti
TPanel(DisplayLabel).Hint := CaptionText;
TPanel(DisplayLabel).ShowH
end
else
try
TLabel(DisplayLabel).Color
TLabel(DisplayLabel).font.
TLabel(DisplayLabel).Capti
TLabel(DisplayLabel).Hint := CaptionText;
TLabel(DisplayLabel).ShowH
except
AppMessage('DisplayPersonN
end;
and i am also compiling with runtime packages ( well i was befor anyway ) but the combination works...
I have noticed that since using delphi 5 and a lot more Dll's and packages things are a little more delicate and i find myself working around a lot of problems like this ! am i the only one ?
Im a bit split on who answered the question it was Madshi, even though sesa did have an influence. I will post an extra 25 for sesa in a new question ETC.
Cheers guys.
Kristian
oh and ps sorry it took me a while to get back but my packages fell apart half way through and i ended up having to remove them by deleting the registry settings just to remove the package so i could recompile it again so i could install it, as every time i tried to compile or uninstall it it would crash delphi..... like i said is it me or is delphi 5 a bit flakey with the use of packages ??
if obj.ClassName = 'TPanel' then ...
This should always work.
Regards, Madshi.