View Issue Details

IDProjectCategoryView StatusLast Update
0001412JEDI VCL00 JVCL Componentspublic2004-04-22 01:10
ReporteranonymousAssigned Touser72 
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionwon't fix 
Product Version 
Target VersionFixed in Version 
Summary0001412: Suggestion
DescriptionI use Delphi 5 Pro, JVCL3 BETA1
JvVCLUtils.FindForm function return only the first instance found of TFormClass. But in the same application two or more instances can have the same TFormClass..!
FindForm function will be more efficient if modified as below.

function FindForm(FormClass: TFormClass; AForm: TForm): Boolean;
var F: integer;
begin
  Result := False;
  if Assigned(AForm) then
  with Screen do
  begin
    for F := 0 to FormCount - 1 do
      if (Forms[F] is FormClass) and (Forms[F] = AForm) then
      begin
        RESULT := TRUE;
        Break
      end
    end
end;

or for more compatibility

function FindForm(FormClass: TFormClass; AForm: TForm = nil): Boolean;
var F: integer;
begin
  Result := False;
  with Screen do
  begin
    for F := 0 to FormCount - 1 do
      if (Forms[F] is FormClass) and ( Assigned(AForm) and (Forms[F] = AForm)) then
      begin
        RESULT := TRUE;
        Break
      end
    end
end;

regards
TagsNo tags attached.

Activities

nestor

2004-03-02 12:19

reporter   ~0003156

Last edited: 2004-03-02 13:12

...
or for more compatibility

function FindForm(FormClass: TFormClass; AForm: TForm = nil): Boolean;
var F: integer;
begin
  Result := False;
  with Screen do
    for F := 0 to FormCount - 1 do
    begin
      if (Forms[F] is FormClass) then
        if Assigned(AForm) then
          Result := Forms[F] = AForm
        else
          RESULT := TRUE;
        If Result then
          Break
    end
end;

edited on: 03-02-04 13:12

user72

2004-03-03 09:11

  ~0003161

I don't quite see the point. If you already have the instance in AForm, why search for it?

nestor

2004-03-03 18:48

reporter   ~0003168

Last edited: 2004-03-03 19:14

I create and free some forms dynamically (to save memory in major accounting application)
I use Onclose event to free the instance (Action := caFree). In this case “MyForm” is free, removed from memory, but it’s pointer still no Nil.
Testing Assigned(Myform) return True.. using MyForm crash the application..
But testing FindForm(TmyForm, MyForm) return False.. I need to create MyForm first…etc...(Very helpful in case where I had more than one instance of the same class Myform1, MyForm2,Myform3)

edited on: 03-03-04 19:05

edited on: 03-03-04 19:14

user72

2004-03-04 04:41

  ~0003173

This to me is bad programming. Either do not use the global form instance (recommended - in fact, remove it altogether) or set it to nil in OnClose:

Action := caFree;
MyForm := nil;

nestor

2004-03-04 05:19

reporter   ~0003175

Thanks I'll do that

Issue History

Date Modified Username Field Change
2004-03-02 12:06 anonymous New Issue
2004-03-02 12:19 nestor Note Added: 0003156
2004-03-02 13:12 nestor Note Edited: 0003156
2004-03-03 09:11 user72 Note Added: 0003161
2004-03-03 09:12 user72 Status new => feedback
2004-03-03 18:48 nestor Note Added: 0003168
2004-03-03 19:05 nestor Note Edited: 0003168
2004-03-03 19:14 nestor Note Edited: 0003168
2004-03-04 04:41 user72 Note Added: 0003173
2004-03-04 05:19 nestor Note Added: 0003175
2004-03-04 08:41 user72 Status feedback => resolved
2004-03-04 08:41 user72 Resolution open => won't fix
2004-03-04 08:41 user72 Assigned To => user72
2004-04-22 01:10 user72 Status resolved => closed