* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
Beginners / Re: Problems readig archive files
« Last post by howardpc on Today at 10:28:23 am »
Code snippets are useless. Show the entire code.

Is kenrot declared as an Integer rather than Single or Double?
In what format are the numbers stored in the text file you are reading?
2
Beginners / Re: Problems readig archive files
« Last post by Handoko on Today at 10:15:28 am »
~~~ sorry off topic ~~~

Hello sir. When posting in this forum you can make your code more readable by using code tag. First you select the text then click the code tag and choose Pascal. See the image below:
3
Android / Re: Android Module Wizard
« Last post by trevor on Today at 10:15:02 am »
How to add 2/3/4/5 lines to all items of Android Native ListView?
4
FPC development / Re: StringReplace extremely slow with big strings
« Last post by CM630 on Today at 10:12:27 am »
@Thaddy, I am not sure that I understood you right and that you understood me. I am replacing Ansi with Ansi in an UTF8 string.

In other words: Strings which I am replacing are with ascii code <127 (basic Latin, &%$# etc). But the sting which contains them may also contain uтf8 characters.
5
Beginners / Re: Problems readig archive files
« Last post by jcaser1948 on Today at 09:50:07 am »
Dear Howard Pc
I Am trying yor solution
Here the code so far  {---------------------------------------------------------------------------}
PROCEDURE TForm1.ReadFile;

VAR
  filename:string;
  LocalMotorname:Textfile;
   sl: TStringList;
   BEGIN
    OpenDialog1.Execute ;

   filename:= OpenDialog1.filename;
    ShowMessage(Filename);
   sl:=TStringList.Create;
           try
    sl.LoadFromFile(OpenDialog1.Filename);
    Assert(sl.Count=81,'Unexpected number of lines in '+OpenDialog1.Filename);
    dia:=sl[0];
    mes:=sl[1];
    anho:=sl[2];
    motortyp:= sl[3];
    Bearbeiter:= sl[4];
    Statorblechnr:= sl[5];
    Rotorblechnr:=sl[6];
    Angebotsnummer:= sl[7];
    kenrot :=StrToFloat(sl[8]);
    schltg := sl[9];
    polzahl              .....
Kenrot ,schltg....are real numbers , since this is a motorcalculationsprogramm.
When  I try to convert Kenrot  from a String to a real number Iget
datenfile1.pas(1949,14) Error: Incompatible types: got "Extended" expected "LongInt"
Any suggestions?
6
General / Re: Robotic arm in Lazarus
« Last post by avra on Today at 09:28:24 am »
Imagine, there are 5 steppers with encoders. Every one in real time should be read, analysed and then some kind of action has to be done with steppers (stop, go on, back, hold position etc.). There is also voltage circuit in case that an encoder is destroyed? And to the RPi are connected other sensors, next, how to manage with acceler/ deceler. of stepper and so on...  That why i decided to separate them from RPi. Simple ATMega8 is very capable
You are right that sync will be lost with plain linux (even RT could loose steps in this case), and I understand using an AVR for offloading realtime work (I did stepper acc/dec ramps with AVRs too). Once you have to make a driver electronics it is tempting to add a microcontroller, especially if you are already familiar with programming them. But maybe Thaddy was talking about using DMA to offload GPIO work from RPi CPU. Take a look at this project. You will see that with RPi DMA even slow Python is capable to drive stepper ramps without loosing sync. Here is a quote from the site:
Quote
Typically there is no way to control stepper motors from Linux runtime environment due to the lack of real time GPIO control. Even kernel based modules can not guarantee precise control of pulses for steppers. However, we can use a separate hardware module, DMA (Direct Memory Access) which provides high precision for GPIO outputs. This module can copy bytes which represent GPIO states from RAM buffer directly to GPIO with some clock based on main chip internal oscillator without using CPU's cores. Using such approach this project generates impulses for moving stepper motors and that is very precise way regardless CPU load and OS time jitter.
This approach also allows to use Python language for this project. Typically, Python is not good choice for real time application, but since project just needs to set up DMA buffers and hardware will do the rest, Python become the perfect choice for easy development of this project.
It might be even good enough for encoder readings without interrupts.

Anyway, I also like the idea of using the AVR for offload work...
7
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 to AnsiString.
8
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?
9
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
10
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.
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