whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

40 Visitors Online


 
...enumerate all TForms of a Project?
Autor: P. Below
Homepage: http://www.teamb.com
[ Print tip ]  

Tip Rating (1):  
     


function EnumResTypes(hMod: THandle; restype, resname: PChar; Lines: TStrings): BOOL; stdcall;
var
  
ms: TMemoryStream;
  rs: TResourceStream;
  S: string;
  i: Integer;
begin
  
Result := True;
  SetLength(S, 10000);
  if Assigned(resname) then
  begin
    
rs := TResourceStream.Create(hinstance, resname, restype);
    try
      try
        
ms := TMemoryStream.Create;
        try
          
ObjectBinaryToText(rs, ms);
          SetLength(S, ms.Size);
          ms.Position := 0;
          ms.read(S[1], ms.Size);

          Lines.Add(resname);
          Lines.Add('Length of data is ' + IntToStr(Length(S)));
          i := Pos(#13, S);
          if i > 0 then
          begin
            
SetLength(S, i - 1);
            Lines.Add(S);
            i := Pos('object', S);
            if i > 0 then
            begin
              
Delete(S, 1, i + 6);
              i := Pos(' ', S);
              if i > 0 then
              begin
                
Lines.Add('Form name is: ' + Copy(S, 1, i - 2));
                Delete(S, 1, i);
                Lines.Add('Form class is: ' + S);
              end;
            end
          end
          else
          begin
            
// Lines.Add('This resource seems not to hold a form');
          
end;
        finally
          
ms.Free
        end;
      except
        
// Lines.Add('This resource is not a form resource');
      
end;
    finally
      
rs.Free;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not 
EnumResourceNames(0, RT_RCDATA, @EnumResTypes, Integer(Memo1.Lines)) then
    
Memo1.Lines.Add('Error, GetLastError Returns ' + IntToHex(GetLastError, 8));
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners