Avatar of formi
Flag for Switzerland asked on

Using Resources in Delphi

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

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Great, that works! Thanks a lot!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck