From 9da9ea12201394415c24db93d32167b6d0c8efec Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 16 Jun 2022 11:54:15 +0000 Subject: [PATCH] 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 --- .../latest_stable/exampleapp/make_res.bat | 2 + .../latest_stable/exampleapp/project1.lpi | 26 +++++------- .../latest_stable/exampleapp/project1.res | Bin 138128 -> 139100 bytes .../latest_stable/exampleapp/scrolltext.lrs | 3 ++ .../latest_stable/exampleapp/scrolltext.res | Bin 0 -> 113 bytes .../latest_stable/exampleapp/scrolltext.txt | 2 +- .../latest_stable/exampleapp/unit1.lfm | 5 ++- .../latest_stable/exampleapp/unit1.pas | 17 ++++++-- .../latest_stable/scrollingtext.pas | 38 +++++++++++++----- 9 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 components/scrolltext/latest_stable/exampleapp/make_res.bat create mode 100644 components/scrolltext/latest_stable/exampleapp/scrolltext.lrs create mode 100644 components/scrolltext/latest_stable/exampleapp/scrolltext.res diff --git a/components/scrolltext/latest_stable/exampleapp/make_res.bat b/components/scrolltext/latest_stable/exampleapp/make_res.bat new file mode 100644 index 000000000..f7934bbe9 --- /dev/null +++ b/components/scrolltext/latest_stable/exampleapp/make_res.bat @@ -0,0 +1,2 @@ +lazres scrolltext.res scrolltext.txt +lazres scrolltext.lrs scrolltext.txt diff --git a/components/scrolltext/latest_stable/exampleapp/project1.lpi b/components/scrolltext/latest_stable/exampleapp/project1.lpi index b42632a74..da20c746c 100644 --- a/components/scrolltext/latest_stable/exampleapp/project1.lpi +++ b/components/scrolltext/latest_stable/exampleapp/project1.lpi @@ -1,11 +1,13 @@ - + + + + - <ResourceType Value="res"/> <UseXPManifest Value="True"/> @@ -14,9 +16,6 @@ <i18n> <EnableI18N Value="True" LFM="False"/> </i18n> - <VersionInfo> - <StringTable ProductVersion=""/> - </VersionInfo> <BuildModes Count="1"> <Item1 Name="Default" Default="True"/> </BuildModes> @@ -24,9 +23,10 @@ <Version Value="2"/> </PublishOptions> <RunParams> - <local> - <FormatVersion Value="1"/> - </local> + <FormatVersion Value="2"/> + <Modes Count="1"> + <Mode0 Name="default"/> + </Modes> </RunParams> <RequiredPackages Count="2"> <Item1> @@ -40,7 +40,6 @@ <Unit0> <Filename Value="project1.lpr"/> <IsPartOfProject Value="True"/> - <UnitName Value="project1"/> </Unit0> <Unit1> <Filename Value="unit1.pas"/> @@ -67,18 +66,15 @@ <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> </SearchPaths> <Linking> + <Debugging> + <DebugInfoType Value="dsDwarf3"/> + </Debugging> <Options> <Win32> <GraphicApplication Value="True"/> </Win32> </Options> </Linking> - <Other> - <CompilerMessages> - <MsgFileName Value=""/> - </CompilerMessages> - <CompilerPath Value="$(CompPath)"/> - </Other> </CompilerOptions> <Debugging> <Exceptions Count="3"> diff --git a/components/scrolltext/latest_stable/exampleapp/project1.res b/components/scrolltext/latest_stable/exampleapp/project1.res index 7c6cf3e4be6fa881cb2f2caa9bda693328155c28..55653795630f092e02e316c1398baeab0ab25dbd 100644 GIT binary patch delta 1016 zcmbu8&u`N(6vtC4!35fFNISaa0tYvCY$r~YRa8hwJ!~LV0*RXw+iRqxiJEMsLMTEU z;J9jk3WweJOSnw@0sILgKU!4A+6xC;^7HfOef8eg7gu{fzVBUtN7wfa0~m&Jb8~q4 ztNnQS{QAK#O;1FuE}yo%Z(-|a>i~E`5~m^${V)pi<)<gb=6TUO$KApHLjXLHrcoG_ ziOIAM0IvffcpFY-GS9%9Fv|siaCMcPrD-zDm3%b@BYD*Qpe%$jWe&uQ+K`ffLBX_w z2yv;DB9dtIu?x(>eo+?to9*o25{3!)T>+VNORn}M<jRszSd=2mV%jC5;r@f=cVmlM zFBO)yxFV1d--VP?41M7SP};7ff(ly^zKz?%cav){*0y5@jtx0d7*dP4&}F_4Igv=) z63Ie1+sGL00CR=3Bd`U1?US+-io>!m3{tKoLjp75Zg#@FJx|YU2LG&a!lIg_C$jjQ z^fyw$`#73r{W`w<+9}A|9d+Woal=^Uc{n}In&hMIB+t{nX=cGh#Uks)VK7UwMCZM- zqB%YunHECKTv=)TxB&xCrr~fdW@_+KM49r;Kj+Gog=aPrZ&hAd_CG~odyA;5H1MKi zTAaQX`J~aO8+~PTBUoov+YX`YtBp37`m1QBVn138$}jw`T&Vua2gb26G)Bfrxn6uu P+Fz1(>ndsA>m2?D@Fg*n delta 62 zcmcb!k7L4ijtL4(;>;73{<BBsmlin|6in7&v|&}qNG(d;oWl5+k=sT;vA8%jHz}vm Su34GAU74M6yD~eIr33(}0TZhL diff --git a/components/scrolltext/latest_stable/exampleapp/scrolltext.lrs b/components/scrolltext/latest_stable/exampleapp/scrolltext.lrs new file mode 100644 index 000000000..24c689f31 --- /dev/null +++ b/components/scrolltext/latest_stable/exampleapp/scrolltext.lrs @@ -0,0 +1,3 @@ +LazarusResources.Add('scrolltext','TXT',[ + 'This text is in a resource.'#13#10 +]); diff --git a/components/scrolltext/latest_stable/exampleapp/scrolltext.res b/components/scrolltext/latest_stable/exampleapp/scrolltext.res new file mode 100644 index 0000000000000000000000000000000000000000..bd4f25c46d2695dd8c5faa460bfb9977540ddb8b GIT binary patch literal 113 zcmZQzU|>)H;{X347|28cvOt~*5dZ(r#SqNk%n-!j&)@@uAq=hz5kL|K1O#9#28NJ~ e%wmO-)QS=XAf1_~kf>0UTAW{6l$@%^%LM?crxR!Z literal 0 HcmV?d00001 diff --git a/components/scrolltext/latest_stable/exampleapp/scrolltext.txt b/components/scrolltext/latest_stable/exampleapp/scrolltext.txt index 881c4feb8..a772ad67f 100644 --- a/components/scrolltext/latest_stable/exampleapp/scrolltext.txt +++ b/components/scrolltext/latest_stable/exampleapp/scrolltext.txt @@ -1 +1 @@ -This is text +This text is in a resource. diff --git a/components/scrolltext/latest_stable/exampleapp/unit1.lfm b/components/scrolltext/latest_stable/exampleapp/unit1.lfm index 1ef4d8b3e..95fc3574e 100644 --- a/components/scrolltext/latest_stable/exampleapp/unit1.lfm +++ b/components/scrolltext/latest_stable/exampleapp/unit1.lfm @@ -8,7 +8,7 @@ object Form1: TForm1 ClientHeight = 363 ClientWidth = 552 Position = poDesktopCenter - LCLVersion = '1.2.4.0' + LCLVersion = '2.3.0.0' object ScrollingText1: TScrollingText Left = 0 Height = 363 @@ -17,7 +17,7 @@ object Form1: TForm1 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' ) - About.Title = 'About About About ScrollingText component' + About.Title = 'About About About About ScrollingText component' About.Height = 280 About.Width = 400 About.Font.Color = clNavy @@ -55,6 +55,7 @@ object Form1: TForm1 'June 2014' ) Font.Height = -13 + LinkFont.Height = -13 TextSource = stResource end object BitBtn1: TBitBtn diff --git a/components/scrolltext/latest_stable/exampleapp/unit1.pas b/components/scrolltext/latest_stable/exampleapp/unit1.pas index 66f9b57c8..cc8f92116 100644 --- a/components/scrolltext/latest_stable/exampleapp/unit1.pas +++ b/components/scrolltext/latest_stable/exampleapp/unit1.pas @@ -4,9 +4,14 @@ unit Unit1; interface +// Both .lrs and .res files can be used. +// Activate the corresponding define for testing. +{$DEFINE LRS_RESOURCE} +{.$DEFINE RES_RESOURCE} + uses Classes, SysUtils, FileUtil, ScrollingText, Forms, Controls, Graphics, - Dialogs, Buttons, StdCtrls; + Dialogs, Buttons, StdCtrls, LResources; type @@ -29,9 +34,10 @@ var implementation {$R *.lfm} +{$IFDEF RES_RESOURCE} + {$R scrolltext.res} +{$ENDIF} -resourcestring - scrolltext='Hello'; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); @@ -39,5 +45,10 @@ begin ScrollingText1.Active:=NOT ScrollingText1.Active; end; +initialization +{$IFDEF LRS_RESOURCE} + {$I scrolltext.lrs} +{$ENDIF} + end. diff --git a/components/scrolltext/latest_stable/scrollingtext.pas b/components/scrolltext/latest_stable/scrollingtext.pas index bc8d391d1..3fbc9f7ce 100644 --- a/components/scrolltext/latest_stable/scrollingtext.pas +++ b/components/scrolltext/latest_stable/scrollingtext.pas @@ -36,12 +36,12 @@ interface uses Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, - ExtCtrls, LCLIntf,LCLTranslator,AboutScrolltextunit; + ExtCtrls, LCLType, LCLIntf, LCLTranslator, AboutScrolltextunit; const C_TEXTFILENAME = 'scrolling.txt'; - C_TEXTRESOURCENAME = 'scrolltext'; //Note: LResources unit needed - C_VERSION = '1.0.2.0'; + C_TEXTRESOURCENAME = 'scrolltext'; //Note: LResources unit needed for .lrs resource + C_VERSION = '1.0.4.0'; type TTextSource = (stStringlist, stTextfile, stResource); @@ -158,6 +158,7 @@ end; procedure TScrollingText.Init; var r: TLResource; + stream: TResourceStream; begin FBuffer.Width := Width; FBuffer.Height := Height; @@ -185,19 +186,34 @@ begin fLines.Add('The file ''' + C_TEXTFILENAME + ''' is missing.'); fLines.Add('It should be in the same folder as your application'); end; + + // Load text from resource string if (fTextSource = stResource) then - - // Load text from resource string begin - r := LazarusResources.Find(fResourceName); - if r = nil then - raise Exception.CreateFmt('Resource ''%s'' is missing',[fResourceName]) - else + // Test for a .res resource first + if FindResource(HInstance, fResourceName, RT_RCDATA) <> 0 then begin - fLines.Clear; - fLines.Add(r.Value); + stream := TResourceStream.Create(HInstance, fResourceName, RT_RCDATA); + 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; + // Are there any lines in the Stringlist? if (fLines.Count = 0) then begin