Warning: Long post
Umph, izgleda da se ne razumemo :)
Probaj ovo:
Code:
var
aSomePropertyReturningAnsi : AnsiString;
aSomePropertyReturningWide : WideString;
begin
// Set the values
aSomePropertyReturningAnsi := #$FF#$FE#$41#$00#$42#$00#$43#$00;
aSomePropertyReturningWide := #$FF#$FE#$41#$00#$42#$00#$43#$00;
// Show the values of each
ShowMessage('aSomePropertyReturningAnsi[1] = '+IntToStr(Ord(aSomePropertyReturningAnsi[1]))); // = 255
ShowMessage('aSomePropertyReturningWide[1] = '+IntToStr(Ord(aSomePropertyReturningWide[1]))); // = 729
end;
Mozes da koristis i funkcije umesto ove dve promenljive, kao i property-je.
Property SomeStringProperty:string je do D2009 vracao AnsiString, a u D2009 vraca Unicode. To znaci da ces, ako inicijalizujes string property na ovaj nacin (da, ruzno je, ali se masovno koristi, kao i jos ruznije varijante sa uzimanjem pointera na pocetak stringa i citanje/pisanje po istom) dobijati razlicite rezultate kasnije, u zavisnosti od toga da li koristis D2009 ili ranije. Kada je spomenuti property deo VCL klase verovatno ces morati da dodajes konverziju rezultata u AnsiString pre daljeg koriscenja. Nije problem kada je u tvom kodu, moze da bude vrlo zapetljano ako je u tudjem.
Sa mreznim protokolima upravo i jeste problem oko toga sta se salje...
Cesto nemas kontrolu nad samim protokolom, tj povezujes se na server ciji je protokol vec definisan standardima ili nekim proprietary dokumentima. U tom smislu, vrlo je bitno da na drugu stranu stignu tacno odredjeni
bajtovi tacno odredjenim redom, cak i kad prenosis tekst.
Evo, skinuh sad development snapshot za Indy 10 od sinoc sa
http://indy.fulgan.com/ZIP/ ..
1) {$IFDEF UNICODE} se pojavljuje tu i tamo u kodu, koliko mogu da vidim, iskljucivo za izbor izmedju *A i *W WinAPI poziva.
2) Vidim da slanje stringa ima i parametar za encoding, sto je pozitivno, mada ostatak koda ne izgleda bas uskladjeno sa D2009. Prica ide preko
Code:
function ToBytes(const AValue: string; const ALength: Integer; const AIndex: Integer = 1;
const AEncoding: TIdEncoding = en7Bit): TIdBytes; overload;
var
LLength: Integer;
begin
EIdException.IfTrue(AEncoding = enDefault, 'No encoding specified.'); {do not localize}
LLength := IndyLength(AValue, ALength, AIndex);
if LLength > 0 then
begin
if AEncoding = enUTF8 then begin
Result := StringToUTF8Bytes(AValue, AIndex, LLength);
end else
begin
// For VCL we just do a byte to byte copy with no translation. VCL uses ANSI or MBCS.
// With MBCS we still map 1:1
SetLength(Result, LLength);
CopyTIdString(AValue, AIndex, Result, 0, LLength);
end;
end else begin
SetLength(Result, 0);
end;
end;
sto nas dovodi do
Code:
procedure CopyTIdString(const ASource: String; const ASourceIndex: Integer;
var VDest: TIdBytes; const ADestIndex: Integer; const ALength: Integer = -1); overload;
{$IFDEF USEINLINE}inline;{$ENDIF}
var
LLength: Integer;
begin
LLength := IndyLength(ASource, ALength, ASourceIndex);
if LLength > 0 then
begin
// TODO: support UTF-8
{$IFDEF DOTNET}
GetEncoder(en7Bit).GetBytes(ASource, ASourceIndex-1, LLength, VDest, ADestIndex);
{$ELSE}
Move(ASource[ASourceIndex], VDest[ADestIndex], LLength);
{$ENDIF}
end;
end;
i
Code:
function IndyLength(const ABuffer: String; const ALength: Integer = -1; const AIndex: Integer = 1): Integer;
{$IFDEF USEINLINE}inline;{$ENDIF}
var
LAvailable: Integer;
begin
Assert(AIndex >= 1);
LAvailable := IndyMax(Length(ABuffer)-AIndex+1, 0);
if ALength < 0 then begin
Result := LAvailable;
end else begin
Result := IndyMin(LAvailable, ALength);
end;
end;
iz cega bih rekao da ovo nece bas raditi kako treba za Unicode. :(