mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 03:29:28 +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/lazloggerdummy.pas svneol=native#text/pascal
|
||||||
components/lazutils/lazloggerprofiling.pas svneol=native#text/pascal
|
components/lazutils/lazloggerprofiling.pas svneol=native#text/pascal
|
||||||
components/lazutils/lazmethodlist.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/lazunicode.pas svneol=native#text/plain
|
||||||
components/lazutils/lazutf16.pas svneol=native#text/pascal
|
components/lazutils/lazutf16.pas svneol=native#text/pascal
|
||||||
components/lazutils/lazutf8.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
|
||||||
./runtests --format=plain --suite=TTestCompReaderWriterPas.TestBaseTypesMaxValues
|
./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:
|
ToDo:
|
||||||
- OnWriteMethodProperty
|
|
||||||
- OnWriteStringProperty
|
|
||||||
- RegisterPascalProperties(aClass,@);
|
- RegisterPascalProperties(aClass,@);
|
||||||
- enum: add unit, avoid nameclash with-do
|
- enum: add unit, avoid nameclash with-do
|
||||||
- custom integer TColor, add unit, avoid nameclash with-do
|
- custom integer TColor, add unit, avoid nameclash with-do
|
||||||
@ -52,8 +27,8 @@ unit TestCompReaderWriterPas;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, typinfo, LazLoggerBase, LazUTF8, LazLogger,
|
Classes, SysUtils, typinfo, LazLoggerBase, LazUTF8, LazLogger, CompWriterPas,
|
||||||
CompWriterPas, fpcunit, testregistry, CodeToolManager, LinkScanner,
|
LazPasReadUtil, fpcunit, testregistry, CodeToolManager, LinkScanner,
|
||||||
CodeToolsStructs, CodeCache, BasicCodeTools, TestStdCodetools, TestGlobals,
|
CodeToolsStructs, CodeCache, BasicCodeTools, TestStdCodetools, TestGlobals,
|
||||||
variants;
|
variants;
|
||||||
|
|
||||||
@ -1985,47 +1960,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
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;
|
procedure TTestCompReaderWriterPas.TestDefineProperites_ListOfStrings;
|
||||||
var
|
var
|
||||||
ARoot: TSimpleControlWithStrings;
|
ARoot: TSimpleControlWithStrings;
|
||||||
@ -2042,11 +1976,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
Expected:=#7'Strings'#1#6#5'First'#6#6'Second'#0#0;
|
Expected:=#7'Strings'#1#6#5'First'#6#6'Second'#0#0;
|
||||||
TestWriteDescendant('TestDefineProperites_ListOfStrings',ARoot,nil,[
|
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;
|
Lines2:=TStringList.Create;
|
||||||
ExecCustomLFM(Lines2,[Expected]);
|
ExecCustomCSP(Lines2,[Expected]);
|
||||||
AssertEquals('read TStrings.Text',ARoot.Lines.Text,Lines2.Text);
|
AssertEquals('read TStrings.Text',ARoot.Lines.Text,Lines2.Text);
|
||||||
|
|
||||||
finally
|
finally
|
||||||
|
@ -6,28 +6,35 @@
|
|||||||
for details about the license.
|
for details about the license.
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
|
|
||||||
Component serialisation drivers for pascal.
|
Component serialisation into Pascal.
|
||||||
|
|
||||||
Works:
|
Author: Mattias Gaertner
|
||||||
- simple properties: integer, strings, events, ...
|
|
||||||
- nested components (e.g. the child controls of a form)
|
|
||||||
- class properties (e.g. TControl.Font)
|
|
||||||
|
|
||||||
ToDo:
|
Working:
|
||||||
- TCollection needs a typecast to the item class
|
- boolean, set of boolean
|
||||||
- variants
|
- char, widechar, custom char, set of custom char
|
||||||
- widestrings need special encoding conversions, but the driver does not
|
- integers, custom int, set of custom int
|
||||||
know, that a widestring is assigned
|
- strings, codepage system and UTF8
|
||||||
- what to do with DefineProperties?
|
- float, currency
|
||||||
- the 'with' can conflict
|
- enum, custom enum range
|
||||||
- circle dependencies:
|
- set of enum, set of custom enum range
|
||||||
Edit1:=TEdit.Create(Form1);
|
- variant: integers, boolean, string, floats, currency
|
||||||
Edit1.AnchorSide[akLeft].Control:=Label1;
|
- method
|
||||||
Label1:=TLabel.Create(Form1);
|
- persistent
|
||||||
Label1.AnchorSide[akTop].Control:=Edit1;
|
- component children, use SetParentComponent or optional Parent:=
|
||||||
- ChildPos
|
- collection
|
||||||
- Flags
|
- IInterfaceComponentReference
|
||||||
- a reader
|
- 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:
|
||||||
|
- RegisterPascalProperties(aClass,@);
|
||||||
}
|
}
|
||||||
|
|
||||||
unit CompWriterPas;
|
unit CompWriterPas;
|
||||||
@ -47,7 +54,7 @@ const
|
|||||||
CSPDefaultSignatureBegin = CSPDefaultSignature+' - Begin';
|
CSPDefaultSignatureBegin = CSPDefaultSignature+' - Begin';
|
||||||
CSPDefaultSignatureEnd = CSPDefaultSignature+' - End';
|
CSPDefaultSignatureEnd = CSPDefaultSignature+' - End';
|
||||||
CSPDefaultAccessClass = 'TPasStreamAccess';
|
CSPDefaultAccessClass = 'TPasStreamAccess';
|
||||||
CSPDefaultExecCustomLFM = 'ExecCustomLFM';
|
CSPDefaultExecCustomCSP = 'ExecCustomCSP';
|
||||||
CSPDefaultMaxColumn = 80;
|
CSPDefaultMaxColumn = 80;
|
||||||
CWPSkipParentName = '-';
|
CWPSkipParentName = '-';
|
||||||
type
|
type
|
||||||
@ -1255,7 +1262,7 @@ begin
|
|||||||
FAssignOp:=':=';
|
FAssignOp:=':=';
|
||||||
FSignature:=CSPDefaultSignature;
|
FSignature:=CSPDefaultSignature;
|
||||||
FMaxColumn:=CSPDefaultMaxColumn;
|
FMaxColumn:=CSPDefaultMaxColumn;
|
||||||
FExecCustomData:=CSPDefaultExecCustomLFM;
|
FExecCustomData:=CSPDefaultExecCustomCSP;
|
||||||
FAccessClass:=CSPDefaultAccessClass;
|
FAccessClass:=CSPDefaultAccessClass;
|
||||||
C:=TAccessComp.Create(nil);
|
C:=TAccessComp.Create(nil);
|
||||||
FDefaultDefineProperties:=TMethod(@C.DefineProperties).Code;
|
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."/>
|
<Description Value="Useful units for Lazarus packages."/>
|
||||||
<License Value="Modified LGPL-2"/>
|
<License Value="Modified LGPL-2"/>
|
||||||
<Version Major="1"/>
|
<Version Major="1"/>
|
||||||
<Files Count="94">
|
<Files Count="95">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Filename Value="LazLoggerImpl.inc"/>
|
<Filename Value="LazLoggerImpl.inc"/>
|
||||||
<Type Value="Include"/>
|
<Type Value="Include"/>
|
||||||
@ -391,8 +391,12 @@
|
|||||||
</Item93>
|
</Item93>
|
||||||
<Item94>
|
<Item94>
|
||||||
<Filename Value="compwriterpas.pas"/>
|
<Filename Value="compwriterpas.pas"/>
|
||||||
<UnitName Value="ComponentStreamPas"/>
|
<UnitName Value="CompWriterPas"/>
|
||||||
</Item94>
|
</Item94>
|
||||||
|
<Item95>
|
||||||
|
<Filename Value="lazpasreadutil.pas"/>
|
||||||
|
<UnitName Value="lazpasreadutil"/>
|
||||||
|
</Item95>
|
||||||
</Files>
|
</Files>
|
||||||
<LazDoc Paths="../../docs/xml/lazutils"/>
|
<LazDoc Paths="../../docs/xml/lazutils"/>
|
||||||
<i18n>
|
<i18n>
|
||||||
|
@ -21,7 +21,7 @@ uses
|
|||||||
StringHashList, TextStrings, Translations, TTCache, TTCalc, TTCMap, TTDebug,
|
StringHashList, TextStrings, Translations, TTCache, TTCalc, TTCMap, TTDebug,
|
||||||
TTError, TTFile, TTGLoad, TTInterp, TTLoad, TTMemory, TTObjs, TTProfile,
|
TTError, TTFile, TTGLoad, TTInterp, TTLoad, TTMemory, TTObjs, TTProfile,
|
||||||
TTRASTER, TTTables, TTTypes, UTF8Process, HTML2TextRender, Laz_AVL_Tree,
|
TTRASTER, TTTables, TTTypes, UTF8Process, HTML2TextRender, Laz_AVL_Tree,
|
||||||
compwriterpas, LazarusPackageIntf;
|
CompWriterPas, LazPasReadUtil, LazarusPackageIntf;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user