Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Text and binary in one stream? | Shortcuts? (https://www.delphipraxis.net/151146-text-binary-one-stream-%7C-shortcuts.html)

WojTec 7. Mai 2010 12:13


Text and binary in one stream? | Shortcuts?
 
Hello guys!

# begin streams

I need to save and read many data types (numbers (int, float), records, arrays and strings) in one file. Problem is with strings. Currently I'm using TStringStream:

Example write:
Delphi-Quellcode:
Buffer := Length(AValue);
AStream.Write(Buffer, 4);

AString.Clear;
AString.WriteString(AValue);

AStream.CopyFrom(AString, 0);
Example read:
Delphi-Quellcode:
Strings := TStringStream.Create;
try
  P := AStream.Position;
  AStream.Position := 0;
  Strings.CopyFrom(AStream, FHeaderSize);
  AStream.Position := P;

  for I := 1 to 8 do
  begin
    AStream.Position := P;
    AStream.Read(buff32, 4);

    Strings.Position := AStream.Position;
    buffS := Strings.ReadString(buff32);

    // ...

    AStream.Position := Strings.Position;
    P := AStream.Position;
  end;
finally
  Strings.Free;
end;
1st at all strings inside file are not Unicode (compiled on D2010). How to make it unicode?
2nd: my method looks very lame, is better method to store strings next to the binary data?

# end streams

# begin shortcuts

2nd my problem is with shortcuts in dynamically created menu items:

Delphi-Quellcode:
if Item.Tag in [1..9] then
  Item.ShortCut := ShortCut(48 + Item.Tag, [ssCtrl, ssAlt])
;
When press Ctrl+Alt+[num 1-9] program starts executing OnClick for ever... Why?

# end shortcuts

shmia 7. Mai 2010 16:56

Re: Text and binary in one stream? | Shortcuts?
 
First you need a nice protocol/file format to encode and decode all these data types.
Bencode could be such a protocol.
If you want to store unicode strings i suggest to read and write the strings as UTF8.

BEncode Parser and Encoding v.1.01

WojTec 7. Mai 2010 17:42

Re: Text and binary in one stream? | Shortcuts?
 
I see that strings are stored as ANSI and don't know how to change encoding :(


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz