ScrollText: Support .res resources. Fix missing resource in exampleapp.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8307 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-06-16 11:54:15 +00:00
parent 5573accbef
commit 9da9ea1220
9 changed files with 61 additions and 32 deletions

View File

@ -0,0 +1,2 @@
lazres scrolltext.res scrolltext.txt
lazres scrolltext.lrs scrolltext.txt

View File

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<Version Value="9"/> <Version Value="12"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<General> <General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="project1"/> <Title Value="project1"/>
<ResourceType Value="res"/> <ResourceType Value="res"/>
<UseXPManifest Value="True"/> <UseXPManifest Value="True"/>
@ -14,9 +16,6 @@
<i18n> <i18n>
<EnableI18N Value="True" LFM="False"/> <EnableI18N Value="True" LFM="False"/>
</i18n> </i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1"> <BuildModes Count="1">
<Item1 Name="Default" Default="True"/> <Item1 Name="Default" Default="True"/>
</BuildModes> </BuildModes>
@ -24,9 +23,10 @@
<Version Value="2"/> <Version Value="2"/>
</PublishOptions> </PublishOptions>
<RunParams> <RunParams>
<local> <FormatVersion Value="2"/>
<FormatVersion Value="1"/> <Modes Count="1">
</local> <Mode0 Name="default"/>
</Modes>
</RunParams> </RunParams>
<RequiredPackages Count="2"> <RequiredPackages Count="2">
<Item1> <Item1>
@ -40,7 +40,6 @@
<Unit0> <Unit0>
<Filename Value="project1.lpr"/> <Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
@ -67,18 +66,15 @@
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<Linking> <Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
<Options> <Options>
<Win32> <Win32>
<GraphicApplication Value="True"/> <GraphicApplication Value="True"/>
</Win32> </Win32>
</Options> </Options>
</Linking> </Linking>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions> </CompilerOptions>
<Debugging> <Debugging>
<Exceptions Count="3"> <Exceptions Count="3">

View File

@ -0,0 +1,3 @@
LazarusResources.Add('scrolltext','TXT',[
'This text is in a resource.'#13#10
]);

View File

@ -1 +1 @@
This is text This text is in a resource.

View File

@ -8,7 +8,7 @@ object Form1: TForm1
ClientHeight = 363 ClientHeight = 363
ClientWidth = 552 ClientWidth = 552
Position = poDesktopCenter Position = poDesktopCenter
LCLVersion = '1.2.4.0' LCLVersion = '2.3.0.0'
object ScrollingText1: TScrollingText object ScrollingText1: TScrollingText
Left = 0 Left = 0
Height = 363 Height = 363
@ -17,7 +17,7 @@ object Form1: TForm1
About.Description.Strings = ( About.Description.Strings = (
'Component that shows a scrolling window.'#13#10'Use Lines property to set text and Active=True'#13#10'to use the component' 'Component that shows a scrolling window.'#13#10'Use Lines property to set text and Active=True'#13#10'to use the component'
) )
About.Title = 'About About About ScrollingText component' About.Title = 'About About About About ScrollingText component'
About.Height = 280 About.Height = 280
About.Width = 400 About.Width = 400
About.Font.Color = clNavy About.Font.Color = clNavy
@ -55,6 +55,7 @@ object Form1: TForm1
'June 2014' 'June 2014'
) )
Font.Height = -13 Font.Height = -13
LinkFont.Height = -13
TextSource = stResource TextSource = stResource
end end
object BitBtn1: TBitBtn object BitBtn1: TBitBtn

View File

@ -4,9 +4,14 @@ unit Unit1;
interface interface
// Both .lrs and .res files can be used.
// Activate the corresponding define for testing.
{$DEFINE LRS_RESOURCE}
{.$DEFINE RES_RESOURCE}
uses uses
Classes, SysUtils, FileUtil, ScrollingText, Forms, Controls, Graphics, Classes, SysUtils, FileUtil, ScrollingText, Forms, Controls, Graphics,
Dialogs, Buttons, StdCtrls; Dialogs, Buttons, StdCtrls, LResources;
type type
@ -29,9 +34,10 @@ var
implementation implementation
{$R *.lfm} {$R *.lfm}
{$IFDEF RES_RESOURCE}
{$R scrolltext.res}
{$ENDIF}
resourcestring
scrolltext='Hello';
{ TForm1 } { TForm1 }
procedure TForm1.Button1Click(Sender: TObject); procedure TForm1.Button1Click(Sender: TObject);
@ -39,5 +45,10 @@ begin
ScrollingText1.Active:=NOT ScrollingText1.Active; ScrollingText1.Active:=NOT ScrollingText1.Active;
end; end;
initialization
{$IFDEF LRS_RESOURCE}
{$I scrolltext.lrs}
{$ENDIF}
end. end.

View File

@ -36,12 +36,12 @@ interface
uses uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, LCLIntf,LCLTranslator,AboutScrolltextunit; ExtCtrls, LCLType, LCLIntf, LCLTranslator, AboutScrolltextunit;
const const
C_TEXTFILENAME = 'scrolling.txt'; C_TEXTFILENAME = 'scrolling.txt';
C_TEXTRESOURCENAME = 'scrolltext'; //Note: LResources unit needed C_TEXTRESOURCENAME = 'scrolltext'; //Note: LResources unit needed for .lrs resource
C_VERSION = '1.0.2.0'; C_VERSION = '1.0.4.0';
type type
TTextSource = (stStringlist, stTextfile, stResource); TTextSource = (stStringlist, stTextfile, stResource);
@ -158,6 +158,7 @@ end;
procedure TScrollingText.Init; procedure TScrollingText.Init;
var var
r: TLResource; r: TLResource;
stream: TResourceStream;
begin begin
FBuffer.Width := Width; FBuffer.Width := Width;
FBuffer.Height := Height; FBuffer.Height := Height;
@ -185,19 +186,34 @@ begin
fLines.Add('The file ''' + C_TEXTFILENAME + ''' is missing.'); fLines.Add('The file ''' + C_TEXTFILENAME + ''' is missing.');
fLines.Add('It should be in the same folder as your application'); fLines.Add('It should be in the same folder as your application');
end; end;
// Load text from resource string
if (fTextSource = stResource) then if (fTextSource = stResource) then
// Load text from resource string
begin begin
r := LazarusResources.Find(fResourceName); // Test for a .res resource first
if r = nil then if FindResource(HInstance, fResourceName, RT_RCDATA) <> 0 then
raise Exception.CreateFmt('Resource ''%s'' is missing',[fResourceName])
else
begin begin
fLines.Clear; stream := TResourceStream.Create(HInstance, fResourceName, RT_RCDATA);
fLines.Add(r.Value); try
fLines.Clear;
fLines.LoadFromStream(stream);
finally
stream.Free;
end;
end else
begin
// Finally, test of a .lrs resource
r := LazarusResources.Find(fResourceName);
if r = nil then
raise Exception.CreateFmt('Resource ''%s'' is missing',[fResourceName])
else
begin
fLines.Clear;
fLines.Add(r.Value);
end;
end; end;
end; end;
// Are there any lines in the Stringlist? // Are there any lines in the Stringlist?
if (fLines.Count = 0) then if (fLines.Count = 0) then
begin begin