Welcome, Guest
Username: Password: Remember me
General discussions, feature requests for CodeTyphon Project and discussions that don't fit in any of the other specific CodeTyphon forum categories.
  • Page:
  • 1

TOPIC:

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8872

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
So as title says: I tried to use FormatDateTime function in a thread and found out it is not thead-safe, no matter what delphi documentation says (fpc/Lazarus documentation doesn't say anything at all regarding thread-safe usage). Even using the function with its own TFormatSettings variable (again as Delphi documentation suggests) doesn't help in CT.
OS: Windows 8.1 Pro
CT: 5.5 / 26.11.2015
FPC: 3.1.1, SVN ver. 49844
So what I'm wondering is if there's no way to use FormatDateTime in threads simultaneously, is there any other (thread-safe) function that I can use? My project is pretty complex, with some, up to many threads spawning and all they require to format the date and/or time. That's why I need such a function asap :D
If there's nothing similar, I'll write my own and probably post in the forum after tests.

P.S. provided a sample test project

File Attachment:

File Name: FormatDate...safe.zip
File Size:198 KB


P.S.S. Wrote something fast to fit my needs, so anyone can feel free to use and/or modify it...
function tmyformatthread.DateTime2Str(format_: string; DT: TDateTime): string;
var
  dd, mm, yy, hh, nn, ss, zzz, dow: word;

 function LZ(What: Integer): string;
 begin
   result:=IntToStr(What);
  if What < 10 then result:='0' + result;
 end;

begin
  DecodeDateFully(DT, yy, mm, dd, dow);
  DecodeTime(DT, hh, nn, ss, zzz);
  result:=format_;
  result:=AnsiReplaceText(result, 'yyyy', LZ(yy));
  result:=AnsiReplaceText(result, 'yy', LZ(yy - 2000));
  result:=AnsiReplaceText(result, 'mm', LZ(mm));
  result:=AnsiReplaceText(result, 'dd', LZ(dd));
  result:=AnsiReplaceText(result, 'hh', LZ(hh));
  result:=AnsiReplaceText(result, 'nn', LZ(nn));
  result:=AnsiReplaceText(result, 'ss', LZ(ss));

  //result:=LZ(dd) + DateSeparator + LZ(mm) + DateSeparator + LZ(yy) + ' ' +
          //LZ(hh) + TimeSeparator + LZ(nn) + TimeSeparator + LZ(ss);
end;   
It's not perfect, but for a couple of minutes, it works perfectly.

Please Log in or Create an account to join the conversation.

Last edit: by Javor.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8873

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Sir
we test your project
how we will find if work OK ?
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8874

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
It's set to use HeapTrc unit (-gh) in Project Options -> Debugging. Upon program close it will show a message box with the freed RAM

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8875

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
is this OK ?

PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8876

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
It's perfect, but please, test it with fpc FormatDateTime function. It leaks. Mine is slow, but doesn't leak any memory.

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8877

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Sir
the previews screen is with
time_:=formatdatetime('dd.mm.yyyy hh:nn:ss', Now, mySettings);

this screen is with
time_:=DateTime2Str('dd.mm.yyyy hh:nn:ss', Now);




CodeTyphon Lab 5.70 revision 5621, Windows 10 Pro 64bits, Typhon64
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8878

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
:huh:
You mean
time_:=formatdatetime('dd.mm.yyyy hh:nn:ss', Now, mySettings);
doesn't make any leaks? What version of CT and FPC are you using? Haven't seen this in bug tracker, or I missed something O.o

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8879

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Sir
all above tests are with CodeTyphon Lab 5.70 revision 5621, Windows 10 Pro 64bits, Typhon64 info
For CodeTyphon we use a Flat-Line Rolling Development Model

Please
-download CT 5.60
-install CT 5.60, !!! DON'T build anything !!!
-Update with CTCenter, to lab CT 5.70 revision 5621
-Build ALL
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8881

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
Thanks, Mr. Sternas, for fast replies. I want just an advice from you, as operations you mentioned will be performed (never tried to update to a LAB version from a CT final release) on my office PC and tomorrow I have to release an update for my project. So do you think I should download CT Lab version, as I use lNet, ZeosDBO (with Postgresql), etc. components and previously found bugs/leaks in both lNet and ZeosDBO (that's why I had to downgrade version of latter one to 7.1.2 stable). Maybe I'll release my update with my function written and then will update to LAB version, as other projects (all written in CT) wait on the queue. If however can be confirmed that at least the bug I found here -> Postgresql leak is fixed, I may try to download and update to lab version before the update is launched. Don't get me wrong - I want to update, but it takes serious time to do everything and right now I'm quite short on time... Not to mention other bugs regarding ZeosDBO and Postgresql (in my case), like for example: char fields are all filled with spaces up to their length when selected from a database and have to be trimmed (every time!!!), encoding to UTF8 was buggy in conjunction with some properties set, etc...

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8882

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Sir
The CodeTyphon it's just the programming "Star Ship"
you can use any version of packages you want, from CT5.5 CT5.x etc
or from Trunk ZeosDBO and Postgresql

But the Lab CT 5.70 has better "Compiler Engine" :)
after a lot of work...

PS: Lab CT 5.70 has and Multi-Projects ability, you can build Terra Multi-Projects with one click..
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8887

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
Morning, Mr. Sternas and everyone :)
Tried what you sugguested, but unfortunately CT 5.6 only allows update to LAB version 5.6.2.1 and not to 5.7 :(

Any other ideas?
Thanks in advance

Please Log in or Create an account to join the conversation.

Last edit: by Javor.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8888

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Sir
until the final release of CT 5.70, the revisions are 0056xx :)
We will close Lab Version with CT 5.70 Final-Stable and revision 005700

PS: Good morning with my second coffee...
PilotLogic Architect and Core Programmer
The following user(s) said Thank You: Javor

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8889

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
OK, started to build a small ide a while ago with the LAB version, will report results regarding memory leaks here.
Thanks for the support!

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8890

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
Report on LAB ver. 5.7
Everything seems to work smoothly (no memory leaks, except the TidHTTPServer, but it's an old one and is a one-time only -> seems the shutting down doesn't actually shut down the TidThread and other stuff property, see the picture below) except... encoding from UTF8 to Sys. Here's my scenario:
server uses Postgresql as a DB server and stores data in UTF8 (as usual).
This server "talks" via JSON to a Delphi XE7 application, which cannot understand UTF8, so characters must be encoded to, let's say UTF8ToSys. Seems like this function doesn't encode anything, because client sees the characters as garbage (UTF8 non-readable). This one didn't present back in CT 5.5 with ZeosDBO 7.2.1 stable. If I decode the string client-side everything seems to work (tried with several fields and they're displayed correctly). Maybe I'm missing something?
P.S. I use both latin and cyrillic (cp1251 windows side) letters

Please Log in or Create an account to join the conversation.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8891

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Sir sorry for the delay
We have meetings for our firsts Programming "Events"
-CT Programming Marathon and
-CT Programming Olympics
more info, I hope soon...

My suggestion is, don't mix applications from different programming worlds
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

FormatDateTime in a thread - any way to use? 8 years 3 months ago #8905

  • Javor
  • Javor's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • M.Sc in Computer Science, (ex-)freelancer
  • Posts: 72
  • Thank you received: 8
Sorry for the delayed answer, but I pretty much busy lately (and haven't released my update yet).

Sternas Stefanos wrote: Sir sorry for the delay
We have meetings for our firsts Programming "Events"
-CT Programming Marathon and
-CT Programming Olympics
more info, I hope soon...

Yes, provide some more info. I'm interested in it :)

Sternas Stefanos wrote: My suggestion is, don't mix applications from different programming worlds

This is cute, but first of all, I don't have a choice and 2nd - why not? After all there are countless ways to do it and all work fine.
Anyway, all seems to work with LAB version. I'll report if I find anything disturbing. So far I have to fight the Indy memory leaks (didn't happen with FTP in previous versions, now I face those)...

Please Log in or Create an account to join the conversation.

  • Page:
  • 1