* * *

Recent Posts

Pages: [1] 2 3 ... 10
General / Re: ABS truncates a Variant float ?
« Last post by ASerge on Today at 02:25:26 am »
Code: Pascal  [Select]
  1. Function ABS(Var V:Variant):Variant; //Current FPC 3.0.4 has Double Type bug.
  2. Begin                                        ;
  3.   If (VarIsNumeric(V)) Then
  4.   if V< 0 Then result := -V else Result := V
  5.   else
  6.    Raise EVariantBadVarTypeError.Create('Contains no Integer or Float for Variant');
  7. end;
var not allow call as Abs(Variant(-5)). And what about Abs(Variant('-5'))?
I suggest the following version
Code: Pascal  [Select]
  1. program Project1;
  5. uses SysUtils, Variants;
  7. function Abs(const V: Variant): Variant;
  8. begin
  9.   Result := V;
  10.   //if Result < 0 then
  11.   //generate code:
  12.   //V2: Variant;
  13.   //V2 := ShortInt(0);
  14.   //if V < V2 then
  15.   if Extended(Result) < 0 then
  16.     Result := -Result;
  17. end;
  19. var
  20.   i: Integer;
  21.   Arr: Variant;
  22. begin
  23.   Arr := VarArrayOf([-35.2, 35.2, -35, -2e-20, '-5.2', 'bad abs value', -$FF, '-$FF']);
  24.   for i := VarArrayLowBound(Arr, 1) to VarArrayHighBound(Arr, 1) do
  25.   try
  26.     Write('Abs(', Arr[i], ')=');
  27.     Writeln(Abs(Arr[i]));
  28.   except
  29.     on E: Exception do
  30.       Writeln('error: ', E.Message);
  31.   end;
  32.   Readln;
  33. end.
General / Re: Problem with sorting string (filepaths)
« Last post by molly on Today at 02:25:14 am »
Well... after some tests. I need to sort paths like in Windows :
Windows is cheating because in explorer all items (at least what you visually see) are (file or directory -name) endpoints

How can I achieve this?
How would you (as a human and also explorer) achieve it ?

answer: by separating the strings (as suggested by Leledumbo) so that you create a new endpoint.

Now it's sorting like that
As written above: make the name of the directory an endpoint and you have your desired result.

So I need that folder named 1.1 comes AFTER folder named 1 not before...  And folder 1.1.1 comes after folder named 1.1 and after folder named 1.

What about this ?
Code: Pascal  [Select]
  1. function NaturalSortIndividualFoldersAsWell(List: TStringList; Index1, Index2: Integer): Integer;
  2. const
  3.   Delims = ['/','\'];
  4. var
  5.   a, b: pnat_char;
  6.   n, n1, n2, nr: integer;
  7.   parta, partb : string;
  8. begin
  9.   n1 := WordCount(List[index1], Delims);
  10.   n2 := WordCount(List[index2], Delims);
  12.   nr := Min(n1, n2);
  14.   for n := 1 to nr do
  15.   begin
  16.     parta := ExtractWord(n, List[index1], Delims);
  17.     partb := ExtractWord(n, List[index2], Delims);
  19.     a := pnat_char(parta);
  20.     b := pnat_char(partb);
  23.     if List.CaseSensitive
  24.     then Result := strnatcmp(a, b)
  25.     else Result := strnatcasecmp(a, b);
  27.     if (Result <> 0) then exit;
  28.   end;
  29. end;

That would also take care of:
But then again he might have a similar problem with some other character.
.. as you can extend the list of delmis easily and to hearts desire  :)
Database / Re: Best database pool library?
« Last post by Trenatos on Today at 02:04:53 am »
I looked at Mormot before but couldn't get it running, that was a while ago though so might be worth looking at again.

Tiopf seems interesting from a pool perspective, but in general I try to avoid ORMs.

Do you know if it's a big task to run straight up queries with it or is it all very tied into the ORM way of doing things?
General / Re: Blowfish and SQLite: some errors.
« Last post by GAN on Today at 01:53:16 am »
It didn't work. Note that the encryption/decryption in memory works well always, the problem only arises when reading the database. Yes I read the thread, in fact I based in your code;)
General / Re: Compiling fpc from svn
« Last post by engkin on Today at 01:47:57 am »
I couldnt find a latest URL where the latest source resides else I would have used trusty wget rather than svn.

What about this:
General / Re: string concantenation problem
« Last post by engkin on Today at 01:39:27 am »
Code: Pascal  [Select]
  1.   Temp := Concat(s1,s2,s3);
Games / Re: Game Contest 2018
« Last post by Paul_ on Today at 01:37:30 am »
The EntityManager would be faster if you used TfpList to hold pointers to all your entities, rather than using a dynamic array.

EntityManager is list of pointers with memory allocation for records, it's probably done in similar way as TfpList.
I was more curious about TCell.List updates. Anyway, I must look at it and try more ways as you write.
General / Re: Blowfish and SQLite: some errors.
« Last post by engkin on Today at 01:29:56 am »
Most likely that's a known bug. You need to free the encodings TEncoding.FreeEncodings. More about it in the 3rd page of this thread.
General / Blowfish and SQLite: some errors.
« Last post by GAN on Today at 12:56:26 am »
Aprox. 95% of strings are encrypted, saved and load OK. But with some words I receive an empty string or an error. Demo proyect is attached.

Works fine with:
jaui oike
jaui oike27

I receive empty strings with;

Error with: tango27

Note: If you add a space at the end of the string before encrypt it, then works fine 100%, so I could solve this problem adding a space to write and removing it after read it.

The question is: Why?

Best regards.
General / string concantenation problem
« Last post by jbmckim on Today at 12:43:46 am »

I'm using the following example to illustrate a problem I'm having.  The program is too large to include the full program context.  When run, 'test str' is not concatenated to the string (that line is embedded in the program and does fail).  There's no other catastrophic or other error.  InsList has 2 entries and 1 in this case is the second entry in a 0 based list.  The 0th element of InsList behaves correctly with 'test str' being properly appended.

My first hope of course is that someone says "Oh hell yes!  That happened to me and here's what you do..."  Barring that, what might I look at/be suspicious of the InsList[1].InsSerial entry?  The InsSerial is a return from an off board piece of hardware.  Something may be off there but it does work calling another device.   

Any thoughts will be appreciated.

Code: Pascal  [Select]
  2. type
  3.   TInsList = specialize TFPGObjectList<TInstrument>;
  5. var
  6.   InsList : TInsList;
  8. Test := IntToStr(InsList[1].RunTimeInsNumber) + InsList[1].InsSerial + 'test str';

Pages: [1] 2 3 ... 10


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