mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 14:00:18 +02:00
lazutils: added unit lazpasreadutil
git-svn-id: trunk@56209 -
This commit is contained in:
parent
acd77c3bb0
commit
fac364fd3b
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -3168,6 +3168,7 @@ components/lazutils/lazloggerbase.pas svneol=native#text/pascal
|
||||
components/lazutils/lazloggerdummy.pas svneol=native#text/pascal
|
||||
components/lazutils/lazloggerprofiling.pas svneol=native#text/pascal
|
||||
components/lazutils/lazmethodlist.pas svneol=native#text/pascal
|
||||
components/lazutils/lazpasreadutil.pas svneol=native#text/plain
|
||||
components/lazutils/lazunicode.pas svneol=native#text/plain
|
||||
components/lazutils/lazutf16.pas svneol=native#text/pascal
|
||||
components/lazutils/lazutf8.pas svneol=native#text/pascal
|
||||
|
@ -3,32 +3,7 @@
|
||||
./runtests --format=plain --suite=TTestCompReaderWriterPas
|
||||
./runtests --format=plain --suite=TTestCompReaderWriterPas.TestBaseTypesMaxValues
|
||||
|
||||
Working:
|
||||
- boolean, set of boolean
|
||||
- char, widechar, custom char, set of custom char
|
||||
- integers, custom int, set of custom int
|
||||
- strings, codepage system and UTF8
|
||||
- float, currency
|
||||
- enum, custom enum range
|
||||
- set of enum, set of custom enum range
|
||||
- variant: integers, boolean, string, floats, currency
|
||||
- method
|
||||
- persistent
|
||||
- component children, use SetParentComponent or optional Parent:=
|
||||
- collection
|
||||
- IInterfaceComponentReference
|
||||
- with ancestor
|
||||
- ancestor: change ComponentIndex -> call SetChildPos
|
||||
- reference foreign root, reference foreign component
|
||||
- create components before setting properties to avoid having to set references
|
||||
later
|
||||
- inline component, csInline, call SetInline, inherited inline, inline on inherited
|
||||
- TComponent.Left/Right via DesignInfo
|
||||
- DefineProperties
|
||||
|
||||
ToDo:
|
||||
- OnWriteMethodProperty
|
||||
- OnWriteStringProperty
|
||||
- RegisterPascalProperties(aClass,@);
|
||||
- enum: add unit, avoid nameclash with-do
|
||||
- custom integer TColor, add unit, avoid nameclash with-do
|
||||
@ -52,8 +27,8 @@ unit TestCompReaderWriterPas;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, typinfo, LazLoggerBase, LazUTF8, LazLogger,
|
||||
CompWriterPas, fpcunit, testregistry, CodeToolManager, LinkScanner,
|
||||
Classes, SysUtils, typinfo, LazLoggerBase, LazUTF8, LazLogger, CompWriterPas,
|
||||
LazPasReadUtil, fpcunit, testregistry, CodeToolManager, LinkScanner,
|
||||
CodeToolsStructs, CodeCache, BasicCodeTools, TestStdCodetools, TestGlobals,
|
||||
variants;
|
||||
|
||||
@ -1985,47 +1960,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
type
|
||||
|
||||
{ TCSPReader }
|
||||
|
||||
TCSPReader = class(TReader)
|
||||
public
|
||||
procedure ReadProperties(Instance: TPersistent);
|
||||
end;
|
||||
|
||||
{ TCSPReader }
|
||||
|
||||
procedure TCSPReader.ReadProperties(Instance: TPersistent);
|
||||
begin
|
||||
while not EndOfList do
|
||||
ReadProperty(Instance);
|
||||
end;
|
||||
|
||||
procedure ExecCustomLFM(Instance: TPersistent; const Data: array of string);
|
||||
var
|
||||
MemStream: TMemoryStream;
|
||||
i: Integer;
|
||||
s: String;
|
||||
Reader: TCSPReader;
|
||||
begin
|
||||
MemStream:=TMemoryStream.Create;
|
||||
Reader:=nil;
|
||||
try
|
||||
for i:=low(Data) to High(Data) do
|
||||
begin
|
||||
s:=Data[i];
|
||||
MemStream.Write(s[1],length(s));
|
||||
end;
|
||||
MemStream.Position:=0;
|
||||
Reader:=TCSPReader.Create(MemStream,1024);
|
||||
Reader.ReadProperties(Instance);
|
||||
finally
|
||||
Reader.Free;
|
||||
MemStream.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestCompReaderWriterPas.TestDefineProperites_ListOfStrings;
|
||||
var
|
||||
ARoot: TSimpleControlWithStrings;
|
||||
@ -2042,11 +1976,11 @@ begin
|
||||
end;
|
||||
Expected:=#7'Strings'#1#6#5'First'#6#6'Second'#0#0;
|
||||
TestWriteDescendant('TestDefineProperites_ListOfStrings',ARoot,nil,[
|
||||
CSPDefaultExecCustomLFM+'(Lines,[#7''Strings''#1#6#5''First''#6#6''Second''#0#0]);',
|
||||
CSPDefaultExecCustomCSP+'(Lines,[#7''Strings''#1#6#5''First''#6#6''Second''#0#0]);',
|
||||
'']);
|
||||
|
||||
Lines2:=TStringList.Create;
|
||||
ExecCustomLFM(Lines2,[Expected]);
|
||||
ExecCustomCSP(Lines2,[Expected]);
|
||||
AssertEquals('read TStrings.Text',ARoot.Lines.Text,Lines2.Text);
|
||||
|
||||
finally
|
||||
|
@ -6,28 +6,35 @@
|
||||
for details about the license.
|
||||
*****************************************************************************
|
||||
|
||||
Component serialisation drivers for pascal.
|
||||
Component serialisation into Pascal.
|
||||
|
||||
Works:
|
||||
- simple properties: integer, strings, events, ...
|
||||
- nested components (e.g. the child controls of a form)
|
||||
- class properties (e.g. TControl.Font)
|
||||
Author: Mattias Gaertner
|
||||
|
||||
Working:
|
||||
- boolean, set of boolean
|
||||
- char, widechar, custom char, set of custom char
|
||||
- integers, custom int, set of custom int
|
||||
- strings, codepage system and UTF8
|
||||
- float, currency
|
||||
- enum, custom enum range
|
||||
- set of enum, set of custom enum range
|
||||
- variant: integers, boolean, string, floats, currency
|
||||
- method
|
||||
- persistent
|
||||
- component children, use SetParentComponent or optional Parent:=
|
||||
- collection
|
||||
- IInterfaceComponentReference
|
||||
- with ancestor
|
||||
- ancestor: change ComponentIndex -> call SetChildPos
|
||||
- reference foreign root, reference foreign component
|
||||
- create components before setting properties to avoid having to set references
|
||||
later
|
||||
- inline component, csInline, call SetInline, inherited inline, inline on inherited
|
||||
- TComponent.Left/Right via DesignInfo
|
||||
- DefineProperties
|
||||
|
||||
ToDo:
|
||||
- TCollection needs a typecast to the item class
|
||||
- variants
|
||||
- widestrings need special encoding conversions, but the driver does not
|
||||
know, that a widestring is assigned
|
||||
- what to do with DefineProperties?
|
||||
- the 'with' can conflict
|
||||
- circle dependencies:
|
||||
Edit1:=TEdit.Create(Form1);
|
||||
Edit1.AnchorSide[akLeft].Control:=Label1;
|
||||
Label1:=TLabel.Create(Form1);
|
||||
Label1.AnchorSide[akTop].Control:=Edit1;
|
||||
- ChildPos
|
||||
- Flags
|
||||
- a reader
|
||||
- RegisterPascalProperties(aClass,@);
|
||||
}
|
||||
|
||||
unit CompWriterPas;
|
||||
@ -47,7 +54,7 @@ const
|
||||
CSPDefaultSignatureBegin = CSPDefaultSignature+' - Begin';
|
||||
CSPDefaultSignatureEnd = CSPDefaultSignature+' - End';
|
||||
CSPDefaultAccessClass = 'TPasStreamAccess';
|
||||
CSPDefaultExecCustomLFM = 'ExecCustomLFM';
|
||||
CSPDefaultExecCustomCSP = 'ExecCustomCSP';
|
||||
CSPDefaultMaxColumn = 80;
|
||||
CWPSkipParentName = '-';
|
||||
type
|
||||
@ -1255,7 +1262,7 @@ begin
|
||||
FAssignOp:=':=';
|
||||
FSignature:=CSPDefaultSignature;
|
||||
FMaxColumn:=CSPDefaultMaxColumn;
|
||||
FExecCustomData:=CSPDefaultExecCustomLFM;
|
||||
FExecCustomData:=CSPDefaultExecCustomCSP;
|
||||
FAccessClass:=CSPDefaultAccessClass;
|
||||
C:=TAccessComp.Create(nil);
|
||||
FDefaultDefineProperties:=TMethod(@C.DefineProperties).Code;
|
||||
|
71
components/lazutils/lazpasreadutil.pas
Normal file
71
components/lazutils/lazpasreadutil.pas
Normal file
@ -0,0 +1,71 @@
|
||||
{
|
||||
*****************************************************************************
|
||||
This file is part of the Lazarus Component Library (LCL)
|
||||
|
||||
See the file COPYING.modifiedLGPL.txt, included in this distribution,
|
||||
for details about the license.
|
||||
*****************************************************************************
|
||||
|
||||
Helper functions for component serialized Pascal.
|
||||
|
||||
Author: Mattias Gaertner
|
||||
}
|
||||
unit LazPasReadUtil;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes;
|
||||
|
||||
{ ExecCustomCSP: Call Instance.DefineProperties with a list of properties in
|
||||
TBinaryObjectWriter format. This function is used by the auto generated
|
||||
Pascal of TCompWriterPas for custom DefineProperties. }
|
||||
procedure ExecCustomCSP(Instance: TPersistent; const Data: array of string);
|
||||
|
||||
implementation
|
||||
|
||||
type
|
||||
|
||||
{ TCSPReader }
|
||||
|
||||
TCSPReader = class(TReader)
|
||||
public
|
||||
procedure ReadProperties(Instance: TPersistent);
|
||||
end;
|
||||
|
||||
{ TCSPReader }
|
||||
|
||||
procedure TCSPReader.ReadProperties(Instance: TPersistent);
|
||||
begin
|
||||
while not EndOfList do
|
||||
ReadProperty(Instance);
|
||||
end;
|
||||
|
||||
procedure ExecCustomCSP(Instance: TPersistent; const Data: array of string);
|
||||
var
|
||||
MemStream: TMemoryStream;
|
||||
i: Integer;
|
||||
s: String;
|
||||
Reader: TCSPReader;
|
||||
begin
|
||||
MemStream:=TMemoryStream.Create;
|
||||
Reader:=nil;
|
||||
try
|
||||
for i:=low(Data) to High(Data) do
|
||||
begin
|
||||
s:=Data[i];
|
||||
MemStream.Write(s[1],length(s));
|
||||
end;
|
||||
MemStream.Position:=0;
|
||||
Reader:=TCSPReader.Create(MemStream,1024);
|
||||
Reader.ReadProperties(Instance);
|
||||
finally
|
||||
Reader.Free;
|
||||
MemStream.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -16,7 +16,7 @@
|
||||
<Description Value="Useful units for Lazarus packages."/>
|
||||
<License Value="Modified LGPL-2"/>
|
||||
<Version Major="1"/>
|
||||
<Files Count="94">
|
||||
<Files Count="95">
|
||||
<Item1>
|
||||
<Filename Value="LazLoggerImpl.inc"/>
|
||||
<Type Value="Include"/>
|
||||
@ -391,8 +391,12 @@
|
||||
</Item93>
|
||||
<Item94>
|
||||
<Filename Value="compwriterpas.pas"/>
|
||||
<UnitName Value="ComponentStreamPas"/>
|
||||
<UnitName Value="CompWriterPas"/>
|
||||
</Item94>
|
||||
<Item95>
|
||||
<Filename Value="lazpasreadutil.pas"/>
|
||||
<UnitName Value="lazpasreadutil"/>
|
||||
</Item95>
|
||||
</Files>
|
||||
<LazDoc Paths="../../docs/xml/lazutils"/>
|
||||
<i18n>
|
||||
|
@ -21,7 +21,7 @@ uses
|
||||
StringHashList, TextStrings, Translations, TTCache, TTCalc, TTCMap, TTDebug,
|
||||
TTError, TTFile, TTGLoad, TTInterp, TTLoad, TTMemory, TTObjs, TTProfile,
|
||||
TTRASTER, TTTables, TTTypes, UTF8Process, HTML2TextRender, Laz_AVL_Tree,
|
||||
compwriterpas, LazarusPackageIntf;
|
||||
CompWriterPas, LazPasReadUtil, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user