Recent

Author Topic: Light LCL (LLCL) - Small Windows executable files v1.02  (Read 34274 times)

Scoops

  • Jr. Member
  • **
  • Posts: 86
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #15 on: October 20, 2015, 05:24:06 pm »
I used Light VCL a couple of years back, great to see it works with Lazarus  :).
For me TStringGrid (As mentioned above) would be a great addition.

Thanks and keep up the good work.

Deepaak

  • Sr. Member
  • ****
  • Posts: 445
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #16 on: November 03, 2015, 05:38:23 am »
How the below procedure works in background

Code: Pascal  [Select][+][-]
  1. procedure TWinControl.ReadProperty(const PropName: string; Reader: TReader);
  2. const Properties: array[0..9] of PChar = (
  3.     'Text',
  4.     'TabOrder', 'TabStop', 'Enabled',
  5.     'OnKeyPress', 'OnKeyDown', 'OnKeyUp',
  6.     'OnMouseDown', 'OnMouseUp', 'OnDblClick'
  7.     );
  8. begin
  9.   case StringIndex(PropName, Properties) of
  10.     0 : fCaption := Reader.StringProperty;
  11.     1 : TabOrder := Reader.IntegerProperty;
  12.     2 : fTabStop := Reader.BooleanProperty;
  13.     3 : fEnabled := Reader.BooleanProperty;
  14.     4 : TMethod(EOnKeyPress)  := FindMethod(Reader);
  15.     5 : TMethod(EOnKeyDown)   := FindMethod(Reader);
  16.     6 : TMethod(EOnKeyUp)     := FindMethod(Reader);
  17.     7 : TMethod(EOnMouseDown) := FindMethod(Reader);
  18.     8 : TMethod(EOnMouseUp)   := FindMethod(Reader);
  19.     9 : TMethod(EOnDblClick)  := FindMethod(Reader);
  20.    else inherited;
  21.   end;
  22. end;      


What is StringIndex. Can't find any resource
Holiday season is online now. :-)

Derit

  • Jr. Member
  • **
  • Posts: 55
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #17 on: November 03, 2015, 10:24:32 am »
hi
i found a bug on two form and main form change the background color
Lazarus Trunk/FPC Trunk/2.6.2/2.6.4

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #18 on: November 03, 2015, 02:42:52 pm »
@Deepaak:
Sorry, I'm not sure about what you mean with 'in background'. Could you precise it, please ?

StringIndex is a non standard (i.e. not present in VCL/LCL) function in "Classes.pas".

As a general comment, as indicated in the documentation (see README.txt) the whole TReader class is not standard in the LLCL (and in the LVCL).


*** Edit ***

@Derit:
Please disregard my former asking. Thanks for the bug reporting.
« Last Edit: November 03, 2015, 03:42:56 pm by ChrisF »

Deepaak

  • Sr. Member
  • ****
  • Posts: 445
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #19 on: November 03, 2015, 07:16:37 pm »
You have created certain predefiend properties like
Code: Pascal  [Select][+][-]
  1. Text, TabOrder etc.
I want to understand the working principle of the above code. How it is stored or used.
Can it be expanded.
Other don't use this method (eg. Lazarus/mse/fpgui). So i am bit confused, And very eager to understand the working principle here, may be i can learn something usefull for my project.
Holiday season is online now. :-)

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8603
  • FPC developer.
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #20 on: November 03, 2015, 07:41:21 pm »
    Based upon the Very Light VCL (LVCL), it's an emulation of a small subset of the standard LCL/VCL,

I've browsed those repositories a bit and I wonder where the sources of Very Light VCL are derived from?

Specially the

Quote
(c)2000,2001 Borland Software Corporation

scares me. 

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #21 on: November 03, 2015, 09:00:43 pm »
You have created certain predefiend properties like
Code: Pascal  [Select][+][-]
  1. Text, TabOrder etc.
I want to understand the working principle of the above code. How it is stored or used.
Can it be expanded.
Other don't use this method (eg. Lazarus/mse/fpgui). So i am bit confused, And very eager to understand the working principle here, may be i can learn something usefull for my project.

There is nothing mysterious: it's just a simple data parsing.

I don't know how mse or fpgui are working, but for the LCL (and also the VCL, the LLCL and the LVCL) the forms data are stored directly in the executable as a resource.

It means that the data present in the .lfm (or the .dfm) files are just stored in the executable as "data"; almost exactly as they are present in the .lfm/dfm files. They are just a bit "organized" but this "organization" is well known and standard; so "decoding" it is very simple.


Let's take an example for one control and it's properties. In the sample coming with the LLCL there is a push-button control called internally "Button3".

Here are the data for this control in unit1.lfm:
Quote
  object Button3: TButton
    Left = 184
    Height = 25
    Top = 44
    Width = 75
    Caption = '&Clear'
    OnClick = Button3Click
    TabOrder = 13
  end

And now the corresponding data present in the resource of the LLCLTest.exe executable file:
Quote
00 00 07 54 42 75 74 74 6F 6E 07 42 75 74 74 6F
6E 33 04 4C 65 66 74 03 B8 00 06 48 65 69 67 68
74 02 19 03 54 6F 70 02 2C 05 57 69 64 74 68 02
4B 07 43 61 70 74 69 6F 6E 06 06 26 43 6C 65 61
72 07 4F 6E 43 6C 69 63 6B 07 0C 42 75 74 74 6F
6E 33 43 6C 69 63 6B 08 54 61 62 4F 72 64 65 72
02 0D

Which is decoded as:
Quote
- 07: Length for the following control class name
- 54 42 75 74 74 6F 6E: Class name = 'TButton'
- 07: Length for the following control name
- 42 75 74 74 6F 6E 33: Control name = 'Button3'
- 04: Length for the following property name
- 4C 65 66 74: Property name = 'Left'
- 03: Type of the property value: 03=vaInt16 (see Classes.pas), which
      means 2 bytes to read for obtaining a 16 bits numerical value
- B8 00: Property value = 184
...
- 07: Length for the following property name
- 43 61 70 74 69 6F 6E: Property name = 'Caption'
- 06: Type of the property value: 06=vaString
- 06: Length for the following string property value
- 26 43 6C 65 61 72: Property value = '&Clear'
...

TReader is the whole mechanism who parses these resource data and dispatches them: controls, properties, sub-properties... Plus a few helpers to read all the possible kind of data.

There is a (virtual) ReadProperty method for the top level TPersistent class (ancestor of all the controls for the LCL/VCL), and each sub-classes adds its own know properties by just overriding this method.

- TComponent just adds the 'Tag' property recognition (see TComponent.ReadProperty in Classes.pas),
- TControl adds 'OnClick' (see TControl.ReadProperty in 'Control.pas'),
- TVisualControl, TWinControl adds several common ones,
- and finally each controls can also add its own specific ones.

StringIndex is just doing a basic string comparison. It compares the property name read from the resource (like 'Caption' in my former sample) with the all known properties for the concerned (sub)control present in the concerned strings array; and returned the index in this array when found.


As you can see, really nothing mysterious...

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #22 on: November 03, 2015, 09:13:44 pm »
    Based upon the Very Light VCL (LVCL), it's an emulation of a small subset of the standard LCL/VCL,

I've browsed those repositories a bit and I wonder where the sources of Very Light VCL are derived from?

Specially the

Quote
(c)2000,2001 Borland Software Corporation

scares me.


I agree that it's quite a legitimate question.

My own guess is that:
Quote
  Emulates the original Delphi/Kylix Cross-Platform Runtime Library
  (c)2000,2001 Borland Software Corporation

means in fact that the LVCL emulates the VCL of Delphi, this latest one being the property of Borland.

But if fact, I guess that only Arnaud Bouchez could answer very precisely; as he is the former owner of this license declaration.

There is a part of the Synopse forum devoted to some various tools (including the LVCL): http://synopse.info/forum/viewforum.php?id=18 .

I think this question might be asked there (Do you think I should ?).

Just a few personal words: Synopse (http://synopse.info) is well-known in the Delphi community and since a while, mainly because of their mORMot Framework. I doubt they have taken the risk to not respect publicly any Delphi license terms.


*** Edit ***

What was exactly the license of Kylix concerning  this part ? It could also be a possible explanation...
« Last Edit: November 03, 2015, 09:17:05 pm by ChrisF »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8603
  • FPC developer.
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #23 on: November 03, 2015, 09:34:11 pm »
There is a part of the Synopse forum devoted to some various tools (including the LVCL): http://synopse.info/forum/viewforum.php?id=18 .

I think this question might be asked there (Do you think I should ?).

Maybe. Maybe I even asked it before, there is a familiar ring to it. But I guess a possible positive outcome could be clarification of the license text and that is probably worth the question alone.

Quote
I doubt they have taken the risk to not respect publicly any Delphi license terms.

It wouldn't be the first time. Many projects were delphi only once, and delphi licenses could be assumed (though strictly not all licenses come with RTL source)

Quote
What was exactly the license of Kylix concerning  this part ? It could also be a possible explanation...

Afaik not API units like classes etc are the same source as Delphi. The only exception is the open edition (aka freeclx), but that was under GPL, which is even worse.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #24 on: November 03, 2015, 10:20:26 pm »
@Derit

Bug fixed (thanks again for the bug report): the GitHub repository for the LLCL (see first post of this topic) has been updated.

(Please note however that the v1.00 release file doesn't contain the updates: they will be included in the next v1.01 version to come.)

I've also added some corrections for control color modifications at run-time (now dynamically updated).

Moreover, the produced executable files are a bit smaller with the updates (but only a few hundred bytes less).


@marcov

OK, I'll post the question in the Synopse forum.
« Last Edit: November 03, 2015, 10:26:56 pm by ChrisF »

Deepaak

  • Sr. Member
  • ****
  • Posts: 445
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #25 on: November 04, 2015, 04:38:04 pm »

I don't know how mse or fpgui are working, but for the LCL (and also the VCL, the LLCL and the LVCL) the forms data are stored directly in the executable as a resource.

It means that the data present in the .lfm (or the .dfm) files are just stored in the executable as "data"; almost exactly as they are present in the .lfm/dfm files. They are just a bit "organized" but this "organization" is well known and standard; so "decoding" it is very simple.

StringIndex is just doing a basic string comparison. It compares the property name read from the resource (like 'Caption' in my former sample) with the all known properties for the concerned (sub)control present in the concerned strings array; and returned the index in this array when found.

As you can see, really nothing mysterious...

Yup, Thank for the detail guide, So ReadProperty() works is to only read information regarding various (components) properties which resides in the executable. How it is written in the executable.

Is there any alternate for StringIndex;
« Last Edit: November 04, 2015, 04:42:47 pm by Deepaak »
Holiday season is online now. :-)

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #26 on: November 04, 2015, 07:48:56 pm »
Yup, Thank for the detail guide, So ReadProperty() works is to only read information regarding various (components) properties which resides in the executable. How it is written in the executable.

More precisely, ReadProperty() is responsible of processing specific treatments for properties belonging to the concerned component class.

It is called by the Reader when parsing the form(s) data, and it can call back the Reader functions/procedures (as the Reader occurrence is passed as a parameter for ReadProperty()).

For instance, for a TWinControl with a 'TabOrder' property, when TWinControl.ReadPRoperty is called with 'TabOrder' and the current Reader as parameters:

- first, it searches if 'TabOrder' is a known property for a TWinControl component. 'TabOrder' is found and corresponds to the second case of the "case of" instruction

- then, executes the concerned instruction(s) for this case:
Code: Pascal  [Select][+][-]
  1.   1 : TabOrder := Reader.IntegerProperty;

- here, it affects the result of the Reader.IntegerProperty function to the integer 'TabOrder' property of the concerned TWinControl component. Reader.IntegerProperty will read 1,2 or 4 bytes in the resource data (according to the type stored for this property control) using the current Reader, and will return a corresponding integer value.


These form(s) data are stored as standard Windows resources in the executable:
https://msdn.microsoft.com/en-us/library/ms648009%28v=vs.85%29.aspx
https://msdn.microsoft.com/library/windows/desktop/aa380599%28v=vs.85%29.aspx
https://en.wikipedia.org/wiki/Resource_%28Windows%29
http://wiki.lazarus.freepascal.org/Lazarus_Resources

They use RT_RCDATA as resource type, and the class name of the form(s) as their name:
Quote
RT_RCDATA : Application-defined resource (raw data).


Extracts of the LLCL code concerning these resource data processing:

In Form.pas:
Code: Pascal  [Select][+][-]
  1. procedure TCustomForm.Load;
  2. var Reader: TReader;
  3. begin
  4.   Reader := TReader.Create(string(ClassName));
  5.   try
  6.     if Reader.Size>4 then
  7.       if Reader.ReadInteger=ord('T')+(ord('P') shl 8)+(ord('F') shl 16)+(ord('0') shl 24) then
  8.         Read(Reader);
  9.   finally
  10.     Reader.Free;
  11.   end;
  12. end;

And in Classes.pas
Code: Pascal  [Select][+][-]
  1. constructor TReader.Create(const ResourceName: string);
  2. var res: THandle;
  3. begin
  4.   res := LLCL_FindResource(hInstance, @ResourceName[1], PChar(RT_RCDATA));
  5.   if res=0 then exit;
  6.   fHandle := LLCL_LoadResource(hInstance,res);
  7.   if fHandle=0 then exit;
  8.   fPointer := LLCL_LockResource(fHandle);
  9.   if fPointer<>nil then
  10.     fSize := SizeOfResource(hInstance,res);
  11.   fStart := fPointer;
  12.   fNotifyLoaded := TList.Create;
  13. end;

As you can see, it checks first for a fixed header ('TPF0') at the beginning of the data, and then begins to process these resource data.



Is there any alternate for StringIndex;

Alternate for StringIndex ? Hum, a lot of ...

As I've written before, StringIndex is just a very basic function:
Code: Pascal  [Select][+][-]
  1. function StringIndex(const s: string; const p: array of PChar): integer;
  2. begin
  3.   result := High(p);
  4.   while (result>=0) and (StrIComp(p[result], pointer(s))<>0) do
  5.     Dec(result);
  6. end;

Or if you prefer a more didactic code, using string variables:
Code: Pascal  [Select][+][-]
  1. function StringIndex(const s: string; const p: array of PChar): integer;
  2. var i: integer;
  3. var sProp: string;
  4. begin
  5.   for i := 0 to Pred(Length(p)) do
  6.     begin
  7.       sProp := string(p[i]);
  8.       if UpperCase(s)=UpperCase(sProp) then
  9.         begin
  10.           result := i;
  11.           exit;
  12.         end;
  13.     end;
  14.   result := -1;
  15. end;
« Last Edit: November 04, 2015, 07:54:59 pm by ChrisF »

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #27 on: November 04, 2015, 07:54:04 pm »
Specially the

Quote
(c)2000,2001 Borland Software Corporation

scares me.

Arnaud Bouchez has kindly answered to my question concerning this declaration: as expected, no material parts copyrighted by Borland are present in the LVCL.

See: http://synopse.info/forum/viewtopic.php?id=2995

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8603
  • FPC developer.
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #28 on: November 04, 2015, 08:44:56 pm »
Arnaud Bouchez has kindly answered to my question concerning this declaration: as expected, no material parts copyrighted by Borland are present in the LVCL.

Clear thanks. If I ever decide to micromanage size I'll look at the L[L|V]CL. But currently I routinely link multiMB resource into binaries, so I doubt it :)

Derit

  • Jr. Member
  • **
  • Posts: 55
Re: Light LCL (LLCL) - Small Windows executable files
« Reply #29 on: November 05, 2015, 01:47:49 am »
hi after i update repository and recompile sample project i found bugs
on form resize draw black color
 
Lazarus Trunk/FPC Trunk/2.6.2/2.6.4

 

TinyPortal © 2005-2018