Every now and then I sometime get the following error “A component named dlgPrinterSettings Already exists.” not necesarry the “dlgprintersettings” everytime, but still, I would like to know what might be the cause of this error in the following piece of code:
procedure TfrmApplicationMain.actPrinterExecute(Sender: TObject);
begin
with TdlgPrinterSettings.Create(self) do
try
ChkEncodeMag.IsChecked := GetUserDataBoolean('MAGNETIC_ENCODING');
ChkEncodeFromDatabase.IsChecked := GetUserDataBoolean('MAGNETIC_DATABASE');
ShowModal;
finally
SetUserData('MAGNETIC_ENCODING',BoolToStr(ChkEncodeMag.IsChecked));
SetUserData('MAGNETIC_DATABASE',BoolToStr(ChkEncodeFromDatabase.IsChecked));
free;
end;
end;
should I use “nil” instead of “self” in the create ?
Just an observation,
if one of the
SetUserDatamethods throws an exception, your TdlgPrinterSettings instance will not get freed. The next time you callactPrinterExecutewould give you the error you mention.ps. Don’t use
with. Declare a local variable and use that. You can search on with & Delphi to find some heated debates about it’s use. I’m not guilt-free myself here but I would not use it in this case.