0

I want to know if it is correct to consider Delphi's Format() function to be an alternative to wsprintf()?

I want to produce the same output as this:

wsprintf( nameFile, "%s_%d_%08x.pfx", nameStore, c_certs, GetTickCount());

Reference

In Delphi, I'm trying to use this:

// Where "Mem" is a TMemoryStream variable
Mem.SaveToFile(NameStore + '_' + IntToStr(I) + '_' + Format('%08x', [GetTickCount]) + '.pfx'); 

Am I'm on the right track?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Yes, they are similar. You could make the Delphi code look even more like the original, but it should work like this. Did you compile and run? Did it work? What is your actual question? – GolezTrol Aug 06 '18 at 22:12
  • @GolezTrol, `You could make the Delphi code look even more like the original`, yes, i already made this, [**see**](https://stackoverflow.com/questions/51614210/how-export-all-my-certificates-of-software-separately-to-a-pfx-file). `Did you compile and run? Did it work?` No, because i'm still not had buy a certificate to store in 'MY' store. The code of previous question compiles fine, but i not have sure that is 100% working (because i still not have a certificate of software in 'MY' location). –  Aug 06 '18 at 22:19
  • You don't need any certificate to test whether or not you can format a string. The C++ code operates on text, not certificates. The skill of debugging lies in breaking things into component parts. – David Heffernan Aug 07 '18 at 07:39
  • OK thank you, this question already was overcomed. Now someone could analise [**this**](https://stackoverflow.com/questions/51614210/how-export-all-my-certificates-of-software-separately-to-a-pfx-file?noredirect=1&lq=1) my previous question and give a suggestion or point some error (if exists) please? I was sad that no one answered my previous question :-(. And now i saw a downvote on my possible solution that i inserted as answer. Please, someone could say what's wrong on my code? –  Aug 07 '18 at 13:17

1 Answers1

1

Yes, that would be the most suitable alternative. You can come pretty close to the same exact syntax.

wsprintf( nameFile, "%s_%d_%08x.pfx", nameStore, c_certs, GetTickCount() );

Delphi code:

NameFile := Format('%s_%d_%.8x.pfx', [namestore, i, GetTickCount]);
Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • ok, thank you. I want know why no one answered my previous question linked here :D. But i think that i followed correctly the suggestion gave on comment. You already worked with Digital Certificate programaticaly in Delphi? –  Aug 07 '18 at 00:11
  • If I had an answer for your other question, I would have posted an answer to it. :-) – Ken White Aug 07 '18 at 00:13
  • ok, i know, i undestood. But independent thi question here,you could see my previous question and say me of some error or something to make better code please? –  Aug 07 '18 at 00:18
  • 2
    I changed the code. In Delphi's Format, `%08x` doesn't work (it does not left-pad with zeroes). You'll have to use `%.8x`. – Rudy Velthuis Aug 07 '18 at 06:51
  • @RudyVelthuis: Yep, you're correct. Didn't look close enough. Thanks for the fix. – Ken White Aug 07 '18 at 12:01