* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
FPC development / Re: StringReplace extremely slow with big strings
« Last post by Thaddy on Today at 09:10:24 am »
If you replace ansi with ansi, plz do NOT use string in Lazarus: that is UTF8. Rename string with AnsiString.
2
Linux / Re: 1.8 Memory Issue - I Think
« Last post by avra on Today at 09:05:07 am »
I determined that everything was eating memory, or at least seemed to be.
Memory leaking or more memory spent then you would expect? How did you come to this conclusion? Show us heaptrc output on application exit. Does this happen on every example project from your Lazarus installation, or just with SDL2? What do you use for SDL2?
3
Third party / Compile for WEB without using Pas2JS
« Last post by cbsistem on Today at 08:40:36 am »
We are compiling a payroll system used in prefectures with more than 650 forms. After 36:00 hours it was already possible to compile the program. Today they start testing in the browser.

https://www.youtube.com/watch?v=zCHEd08BhSk

Cristiano Barbosa
4
FPC development / Re: StringReplace extremely slow with big strings
« Last post by CM630 on Today at 08:08:36 am »
Thanks, I looked at the code... since it uses Posex, I have a bad feeling it won't works with UTF8... ?

Until now I used this code from Lazarus bugzilla:

Code: Pascal  [Select]
  1. //ANSI
  2. Function StringReplaceNew(const S, OldPattern, NewPattern: string;  Flags: TReplaceFlags): string;
  3. var
  4.   OldPat,Srch: string; // Srch and Oldp can contain uppercase versions of S,OldPattern
  5.   PatLength,NewPatLength,P,Cnt,PatCount,PrevP: Integer;
  6.   c,d: pchar;
  7. begin
  8.   PatLength:=Length(OldPattern);
  9.   if PatLength=0 then begin
  10.     Result:=S;
  11.     exit;
  12.   end;
  13.  
  14.  
  15.   if rfIgnoreCase in Flags then begin
  16.     Srch:=AnsiUpperCase(S);
  17.     OldPat:=AnsiUpperCase(OldPattern);
  18.   end else begin
  19.     Srch:=S;
  20.     OldPat:=OldPattern;
  21.   end;
  22.  
  23.  
  24.   PatLength:=Length(OldPat);
  25.   if Length(NewPattern)=PatLength then begin
  26.     //Result length will not change
  27.     Result:=S;
  28.     P:=1;
  29.     repeat
  30.       P:=PosEx(OldPat,Srch,P);
  31.       if P>0 then begin
  32.         move(NewPattern[1],Result[P],PatLength);
  33.         if not (rfReplaceAll in Flags) then exit;
  34.         inc(P,PatLength);
  35.       end;
  36.     until p=0;
  37.   end else begin
  38.     //Different pattern length -> Result length will change
  39.     //To avoid creating a lot of temporary strings, we count how many
  40.     //replacements we're going to make.
  41.     P:=1; PatCount:=0;
  42.     repeat
  43.       P:=PosEx(OldPat,Srch,P);
  44.       if P>0 then begin
  45.         inc(P,PatLength);
  46.         inc(PatCount);
  47.         if not (rfReplaceAll in Flags) then break;
  48.       end;
  49.     until p=0;
  50.     if PatCount=0 then begin
  51.       Result:=S;
  52.       exit;
  53.     end;
  54.     NewPatLength:=Length(NewPattern);
  55.     SetLength(Result,Length(S)+PatCount*(NewPatLength-PatLength));
  56.     P:=1; PrevP:=0;
  57.     c:=pchar(Result); d:=pchar(S);
  58.     repeat
  59.       P:=PosEx(OldPat,Srch,P);
  60.       if P>0 then begin
  61.         Cnt:=P-PrevP-1;
  62.         if Cnt>0 then begin
  63.           Move(d^,c^,Cnt);
  64.           inc(c,Cnt);
  65.           inc(d,Cnt);
  66.         end;
  67.         if NewPatLength>0 then begin
  68.           Move(NewPattern[1],c^,NewPatLength);
  69.           inc(c,NewPatLength);
  70.         end;
  71.         inc(P,PatLength);
  72.         inc(d,PatLength);
  73.         PrevP:=P-1;
  74.         if not (rfReplaceAll in Flags) then break;
  75.       end;
  76.     until p=0;
  77.     Cnt:=Length(S)-PrevP;
  78.     if Cnt>0 then Move(d^,c^,Cnt);
  79.   end;
  80. end;    

but it makes mess with UTF8 strings (even though I am replacing ansi strings with ansi strings).
So I tried to modify it to:


Code: Pascal  [Select]
  1. //UTF8
  2. Function StringReplaceNew(const S, OldPattern, NewPattern: string;  Flags: TReplaceFlags): string;
  3. var
  4.   OldPat,Srch: string; // Srch and Oldp can contain uppercase versions of S,OldPattern
  5.   PatLength,NewPatLength,P,Cnt,PatCount,PrevP: Integer;
  6.   c,d: pchar;
  7. begin
  8.   PatLength:=utf8Length(OldPattern);
  9.   if PatLength=0 then begin
  10.     Result:=S;
  11.     exit;
  12.   end;
  13.  
  14.  
  15.   if rfIgnoreCase in Flags then begin
  16.     Srch:=UTF8UpperCase(S);
  17.     OldPat:=UTF8UpperCase(OldPattern);
  18.   end else begin
  19.     Srch:=S;
  20.     OldPat:=OldPattern;
  21.   end;
  22.  
  23.  
  24.   PatLength:=utf8Length(OldPat);
  25.   if utf8Length(NewPattern)=PatLength then begin
  26.     //Result length will not change
  27.     Result:=S;
  28.     P:=1;
  29.     repeat
  30.       P:=utf8Pos(OldPat,Srch,P);
  31.       if P>0 then begin
  32.         move(NewPattern[1],Result[P],PatLength);
  33.         if not (rfReplaceAll in Flags) then exit;
  34.         inc(P,PatLength);
  35.       end;
  36.     until p=0;
  37.   end else begin
  38.     //Different pattern length -> Result length will change
  39.     //To avoid creating a lot of temporary strings, we count how many
  40.     //replacements we're going to make.
  41.     P:=1; PatCount:=0;
  42.     repeat
  43. //      P:=utf8Pos(OldPat,Srch,P);   //This counts only the occurences of the sougth string, so there is possibly no reason to use UFT8Pos, whish is extremely slow
  44.       P:=Posex(OldPat,Srch,P);
  45.       if P>0 then begin
  46.         inc(P,PatLength);
  47.         inc(PatCount);
  48.         if not (rfReplaceAll in Flags) then break;
  49.       end;
  50.     until p=0;
  51.     if PatCount=0 then begin
  52.       Result:=S;
  53.       exit;
  54.     end;
  55.     NewPatLength:=utf8Length(NewPattern);
  56.     SetLength(Result,utf8Length(S)+PatCount*(NewPatLength-PatLength));
  57.     P:=1; PrevP:=0;
  58.     c:=pchar(Result); d:=pchar(S);
  59.     repeat
  60.       P:=utf8Pos(OldPat,Srch,P);
  61.       if P>0 then begin
  62.         Cnt:=P-PrevP-1;
  63.         if Cnt>0 then begin
  64.           Move(d^,c^,Cnt);
  65.           inc(c,Cnt);
  66.           inc(d,Cnt);
  67.         end;
  68.         if NewPatLength>0 then begin
  69.           Move(NewPattern[1],c^,NewPatLength);
  70.           inc(c,NewPatLength);
  71.         end;
  72.         inc(P,PatLength);
  73.         inc(d,PatLength);
  74.         PrevP:=P-1;
  75.         if not (rfReplaceAll in Flags) then break;
  76.       end;
  77.     until p=0;
  78.     Cnt:=utf8Length(S)-PrevP;
  79.     if Cnt>0 then Move(d^,c^,Cnt);
  80.   end;
  81. end;
I have no idea if it works properly, but is extremely slow.  :'(  It seems to me that utf8Pos is the bottle neck. A very narrow one.
5
Hello everybody.

I downloaded the tiOPF framework v2.5.0.1229 from the official site.
When I try to compile, I get an error.

tiBaseObject.pas(16,19) Error: No matching implementation for interface method "QueryInterface(constref TGuid;out <Formal type>):LongInt; StdCall;" found

How to fix it?
6
its badly named, its not an owner in the component sense. It is the container, it is used by its code to access the grid and its editors as needed at runtime. The owner mechanism is introduced in the TComponent.
7
You say it has no owner ?

 then why was I able to assign an owner ? also, it required one..
TItemProp.Create

Declaration

Source position: valedit.pas line 40

public constructor TItemProp.Create(
  AOwner: TValueListEditor
);

This is from the help file supplied.

 if what you say is true, then there is a bug because it requires an owner to create a TitemProp.

8
Linux / Re: 1.8 Memory Issue - I Think
« Last post by taazz on Today at 04:05:54 am »
Hi, I have been away from Lazarus for several months, so I installed the latest 1.8 version using the deb packages on Sourceforge. I wiped everything Lazarus and FPC from the machine first, then locked the package manager so that it would not try to overwrite the installation with Debian repository packages.

I then started a new project using SDL, which is new to me,  and immediately ran into memory issues, with the machine locking up repeatedly. After beating my head against the wall for several days, I determined that everything was eating memory, or at least seemed to be.

So I did a full Debian update, rebuilt the IDE, and rebooted to a clean XFce4 desktop and started a new empty project (graphical application). I did nothing with it except enable the heaptrc unit. 

When I built and ran the empty project then immediately clicked on the form's close button, heaptrc showed 767 memory blocks allocated and freed. But when I dragged the empty form around rapidly for a few seconds, I got ghost trails and a heaptrc reading in the thousands of memory blocks allocated and freed.
that's how things work memory block are allocated when needed and free when they are not needed any longer as long as the total is 0 then you have leaks elsewhere.
9
if you do this..

 Create a TItemProp and populate it with all its inners etc.. and then do this..

 ValueListEditor.ItemProps
  • := ANewlyCreatedItemProp;

 it uses  this..
Code: Pascal  [Select]
  1. procedure TValueListEditor.SetItemProp(const AKeyOrIndex: Variant; AValue: TItemProp);
  2. begin
  3.   FStrings.GetItemProp(AKeyOrIndex).Assign(AValue);
  4. end;                

As you can see, it is assigning.. not replacing.

That's by design, external data will be copied in internally managed structures.

There is an Assign that can do this and thus not take claim.
Lost me there, there is only one assign usage.
When I create a TitemProp.Create(ValueListEditorInstant) and  use the := , it does work
because it simiply assigns the values.
after that you need to destroy it too, it is an externaly managed structure the component will not touch it.
But using HeapTrc, it leads to massive memory leaks. because the ItemProp I made never gets freed

apparently there is a ready made ItemProp for each entry in the list which is fine but it would be nice
however, if you are assigning the owner to it that it should be getting released!
1) Itemprop does not have an owner, ItemProplist is based on a TObjectList which by default will destroy all its objects when it gets freed. My advice, stop create Titemprop and access them directly eg
Code: Pascal  [Select]
  1. ANewlyCreatedItemProp := ValueListEditor.ItemProps[vRow];
  2.  
after that change its values and move to the row without destroying it.
10
if you do this..

 Create a TItemProp and populate it with all its inners etc.. and then do this..

 ValueListEditor.ItemProps
  • := ANewlyCreatedItemProp;


 it uses  this..
Code: Pascal  [Select]
  1. procedure TValueListEditor.SetItemProp(const AKeyOrIndex: Variant; AValue: TItemProp);
  2. begin
  3.   FStrings.GetItemProp(AKeyOrIndex).Assign(AValue);
  4. end;                

As you can see, it is assigning.. not replacing.

There is an Assign that can do this and thus not take claim.

 When I create a TitemProp.Create(ValueListEditorInstant) and  use the := , it does work
because it simiply assigns the values.

 But using HeapTrc, it leads to massive memory leaks. because the ItemProp I made never gets freed

apparently there is a ready made ItemProp for each entry in the list which is fine but it would be nice
however, if you are assigning the owner to it that it should be getting released!

Pages: [1] 2 3 ... 10

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus