Using Resources in Delphi

formi used Ask the Experts™
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;
    InfoBlock: HRSRC;
    GlobalMemoryBlock: HGLOBAL;
  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));

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

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

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

Do more with

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


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