Cześć, opisując pokrótce problem: tworzę dynamicznie formularz, na nim obiekt TMemo. Na pewno tworzy się prawidłowo bo po TForm.Show TMemo jest widoczny. Niestety Potem FindComponent go nie znajduje...
Fragment kodu:
procedure ShowDebugWindow;
var
mMemo:TMemo;
begin
try
try
if not Assigned(fDebug) then
begin
fDebug := TForm.Create(nil);
with fDebug do
begin
OnClose := CloseDebugWindow;
Caption := self.ClassName + ' - debug statistics';
Width := 900;
Height := 600;
Position := poScreenCenter;
end;
mMemo := TMemo.CreateParented(fDebug.Handle);
with mMemo do
begin
Name := 'memoLog';
Parent := fDebug;
Align := alClient;
ReadOnly := True;
Font.Name := 'Consolas';
Font.Color := clMenuBar;
Font.Size := 8;
Color := clWindowFrame;
BorderStyle := bsNone;
Clear;
end;
fDebug.Show;
end
else
begin
fDebug.Show;
fDebug.BringToFront;
end;
finally
end;
except
on e:exception do ServeException(e, 'ShowDebugWindow');
end;
end;
Poszukiwanie wspomnianego memo:
procedure AddDebugInfo(Info:string; Method:string='');
var
Memo:TMemo;
begin
if Assigned(fDebug) then
begin
fDebug.ComponentCount; // <- zwraca 0
if (fDebug.FindComponent('memoLog') is TMemo) then // <- nie zwraca nic
begin
memo := fDebug.FindComponent('memoLog') as TMemo;
if Method <> '' then
Memo.Lines.Insert(0, Format('%s: %s -> %s',[FormatDateTime('hh:nn:ss.zzz', Now), method, info]))
else
Memo.Lines.Insert(0, Format('%s: %s',[FormatDateTime('hh:nn:ss.zzz', Now), info]));
end;
end;
end;
Dlaczego tak się dzieje?