Using Resources in Delphi

formi
formi used Ask the Experts™
on
I'm using Delphi2010 and try the first time to deal with "Resources". So I tried to create a resourcefile from a simple textfile and compiled it with BRCC32.EXE to a myResource.res. In the Delphi-project I embed the file with {$R myResource.res}

Then I found some code to load the text in a memo-field. The "loadResource"-methode raises an error "invalid parameter". If I open the exe-file with a resource-editor I wonder that I can not see my resource that I embedded.

Shouldn't I see that resource in the exe-file?? Where could be the problem?

Here is the code I load the resource:
{$R *.dfm}
{$R FormicaUpd.res}

function GetResourceAsPointer(ResName: pchar; ResType: pchar;
  out Size: longword): pointer;
var
    InfoBlock: HRSRC;
    GlobalMemoryBlock: HGLOBAL;
begin
  InfoBlock := FindResource(hInstance, resname, restype);
  if InfoBlock = 0 then
    if size = 0 then
       raise Exception.Create(SysErrorMessage(GetLastError));
     GlobalMemoryBlock := LoadResource(hInstance, InfoBlock);
     if GlobalMemoryBlock = 0 then
       raise Exception.Create(SysErrorMessage(GetLastError));
     Result := LockResource(GlobalMemoryBlock);
     if Result = nil then
       raise Exception.Create(SysErrorMessage(GetLastError));
   end;

   function GetResourceAsString(ResName: pchar; ResType: pchar): string;
   var
     ResData: PChar;
     ResSize: Longword;
   begin
     ResData := GetResourceAsPointer(resname, restype, ResSize);
     SetString(Result, ResData, ResSize);
   end;

procedure getResource;
var
     sample_txt: pointer;
     size: longword;
begin
  F_Main.Memo1.Lines.Text := GetResourceAsString('langDe', 'text');
end;

and in the res-file I can see the "Text / langDe / German resource
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Great, that works! Thanks a lot!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial