How to list all data modules opened in an Application? lazarus / 31-LCL ---------------------------------------------------------------------- vfclists · 2013-03-05 23:19 When I am opening a form and need to check whether an instance of the form exists I use this code: Code: [Select]function FindFormT(formClass: string):TForm; var   i, j:integer;   upFormClass: string; begin   result := nil;   upformClass := 'T' + UpperCase(formClass);   for i := 0 to Screen.FormCount-1 do   begin     if UpperCase(Screen.Forms[i].ClassName) = upFormClass then     begin       result := Screen.Forms[i];     end;  end; end;  What equivalent code should be used for data modules? Does the Application object have a data module count? ---------------------------------------------------------------------- taazz · 2013-03-06 05:07 Quote from: vfclists on March 06, 2013, 12:19:02 am When I am opening a form and need to check whether an instance of the form exists I use this code: Code: [Select]function FindFormT(formClass: string):TForm; var   i, j:integer;   upFormClass: string; begin   result := nil;   upformClass := 'T' + UpperCase(formClass);   for i := 0 to Screen.FormCount-1 do   begin     if UpperCase(Screen.Forms[i].ClassName) = upFormClass then     begin       result := Screen.Forms[i];     end;  end; end;  What equivalent code should be used for data modules? Does the Application object have a data module count? No but the screen object does take a look at Screen.DataModuleCount; and  Screen.DataModules[] properties. Just a question do you have forms in dlls? ---------------------------------------------------------------------- vfclists · 2013-03-06 10:21 No, I don't have forms in dlls. Is there some reason why you are asking? Quote from: taazz on March 06, 2013, 06:07:01 amNo but the screen object does take a look at Screen.DataModuleCount; and  Screen.DataModules[] properties. Just a question do you have forms in dlls? ---------------------------------------------------------------------- taazz · 2013-03-06 10:27 because I would code the above routine as Code: [Select]function FindForm(const aClass:TClass):TForm; var   vCnt: Integer; begin   for vCnt := 0 to Screen.FormCount -1 do     if Screen.Forms[vCnt].ClassType = aClass then begin       Result := Screen.Forms[vCnt];       Break;     end; end; Calling it like FindForm(TForm3); that will not work if the form is in a dll though. ---------------------------------------------------------------------- vfclists · 2013-03-06 12:22 You learn something new everyday Do you use form dlls in Lazarus on Windows, and Linux as well? I am thinking of it as something that will minimize my compile-edit-debug cycles? Quote from: taazz on March 06, 2013, 11:27:47 ambecause I would code the above routine as Code: [Select]function FindForm(const aClass:TClass):TForm; var   vCnt: Integer; begin   for vCnt := 0 to Screen.FormCount -1 do     if Screen.Forms[vCnt].ClassType = aClass then begin       Result := Screen.Forms[vCnt];       Break;     end; end; Calling it like FindForm(TForm3); that will not work if the form is in a dll though. ---------------------------------------------------------------------- taazz · 2013-03-06 17:13 No I don't, using the forms from dlls will increase your debug cycles, you see any small change on the internals of your program might trigger a SIGSEGV exception on the dll if they are not compiled as well with the changes in. This makes it harder to debug not easier.