troubleshooting Question

Using Resources in Delphi

Avatar of formi
formiFlag for Switzerland asked on
2 Comments1 Solution804 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros