* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
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;
  2. {$APPTYPE CONSOLE}
  3. {$MODE OBJFPC}
  4.  
  5. uses SysUtils, Variants;
  6.  
  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;
  18.  
  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.
2
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

Quote
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.

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

Quote
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);
  11.  
  12.   nr := Min(n1, n2);
  13.  
  14.   for n := 1 to nr do
  15.   begin
  16.     parta := ExtractWord(n, List[index1], Delims);
  17.     partb := ExtractWord(n, List[index2], Delims);
  18.  
  19.     a := pnat_char(parta);
  20.     b := pnat_char(partb);
  21.  
  22.  
  23.     if List.CaseSensitive
  24.     then Result := strnatcmp(a, b)
  25.     else Result := strnatcasecmp(a, b);
  26.  
  27.     if (Result <> 0) then exit;
  28.   end;
  29. end;
  30.  

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  :)
3
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?
4
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;)
5
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:
ftp://ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip
6
General / Re: string concantenation problem
« Last post by engkin on Today at 01:39:27 am »
Try:
Code: Pascal  [Select]
  1.   Temp := Concat(s1,s2,s3);
  2.  
7
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.
8
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.
9
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:
)(@3849lñ.kd88hoiujhiou
jkgakglaghiasughuiao
jaui oike
jaui oike27
jauioike27
tango272
raven27

I receive empty strings with;
gaston27
gasto27
mal

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.
10
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]
  1.  
  2. type
  3.   TInsList = specialize TFPGObjectList<TInstrument>;
  4.  
  5. var
  6.   InsList : TInsList;
  7.  
  8. Test := IntToStr(InsList[1].RunTimeInsNumber) + InsList[1].InsSerial + 'test str';

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