13.3 Using string tables.

String tables can be used to store and retrieve large collections of strings in your application.

A string table looks as follows:

STRINGTABLE { 1, "hello World !"  
              2, "hello world again !"  
              3, "last hello world !" }

You can compile this (we assume the file is called tests.rc) as follows:

windres -i tests.rc -o tests.res

And this is the way to retrieve the strings from your program:

program tests;  
 
{$mode objfpc}  
 
Uses Windows;  
 
{$R *.res}  
 
  Function LoadResourceString (Index : longint): Shortstring;  
 
  begin  
    SetLength(Result,LoadString(FindResource(0,Nil,RT_STRING),  
                                Index,  
                                @Result[1],  
                                SizeOf(Result))  
             )  
  end;  
 
Var  
    I: longint;  
 
begin  
  For i:=1 to 3 do  
    Writeln (Loadresourcestring(I));  
end.

The call to FindResource searches for the stringtable in the compiled-in resources. The LoadString function then reads the string with index i out of the table, and puts it in a buffer, which can then be used. Both calls are in the windows unit.