Einzelnen Beitrag anzeigen

davtix

Registriert seit: 29. Mai 2003
Ort: Berlin
87 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#45

AW: Überprüfen ob ein Objekt existiert aber wie?

  Alt 27. Dez 2020, 20:55
Code:
unit unitname;

interface

uses System.Classes,


function FindComponentEx(const Name: string): TComponent;
var
  FormName: string;
  CompName: string;
  P: Integer;
  Found: Boolean;
  Form: TForm;
  I: Integer;
begin
  // Split up in a valid form and a valid component name
  if ( Name = '' ) then
    begin
      EXIT;

      raise Exception.Create('No valid form name given');


    end;

  P := Pos('.', Name);
  if P = 0 then
  begin
    EXIT;
    raise Exception.Create('No valid form name given');
  end;
  FormName := Copy(Name, 1, P - 1);
  CompName := Copy(Name, P + 1, High(Integer));
  Found   := False;
  // find the form
  for I := 0 to Screen.FormCount - 1 do
  begin
    Form := Screen.Forms[I];
    // case insensitive comparing
    if AnsiSameText(Form.Name, FormName) then
    begin
      Found := True;
      Break;
    end;
  end;
  if Found then
  begin
    for I := 0 to Form.ComponentCount - 1 do
    begin
      Result := Form.Components[I];
      if AnsiSameText(Result.Name, CompName) then Exit;
    end;
  end;
  Result := nil;
end;
Code:
 
    procedure oder function .... ;
    var compo :TComponent;
    begin
 
        compo := nil;
        compo := FindComponentEx( 'Form4.tempStringGrid101' );
        if ( compo <> nil ) and (compo.ClassType = TJvStringGrid ) then
          begin
            log(9,'add_Entry_database->tempSG4 exist --> FreeAndNil tempSG4');
            //compo:= nil;
            TJvStringGrid( compo ).Free;
          end;
   
     end;

Geändert von davtix (27. Dez 2020 um 21:00 Uhr) Grund: fehler
  Mit Zitat antworten Zitat