🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.delphi
4 messages
4 total messages Started by konsul675 Thu, 05 Jan 2017 14:00
Typy generyczne
#345517
Author: konsul675
Date: Thu, 05 Jan 2017 14:00
21 lines
1389 bytes
Delphi XE2

definicja 
property listaDoc : TDictionary<String,String>

jak wylistować wszystkie klucze i wszystkie "value"

coś ala 

result:= listaDoc.ITEMS.text

lub pętlą

for i := 0 to main.listaDoc.Count-1 do
    begin


      result:=result+listaDoc.items[i];
    end;

ewentualnie jak to zrobić?
Re: Typy generyczne
#345519
Author: Adam Siwoń
Date: Thu, 05 Jan 2017 14:07
39 lines
1861 bytes
W dniu 2017-01-05 o 15:00, konsul675@gmail.com pisze:
> Delphi XE2
>
> definicja
> property listaDoc : TDictionary<String,String>
>
> jak wylistować wszystkie klucze i wszystkie "value"
>
> coś ala
>
> result:= listaDoc.ITEMS.text
>
> lub pętlą
>
> for i := 0 to main.listaDoc.Count-1 do
>     begin
>
>
>       result:=result+listaDoc.items[i];
>     end;
>
> ewentualnie jak to zrobić?
>

To działa w XE4:
   lDict: TDictionary<String,String>;
   item: TPair<String,String>;
begin
   lDict := TDictionary<String,String>.Create;
   for item in lDict do
   begin
     Key := item.Key;
     Text := item.Value;
   end;


-- 
z pozdrowieniami
Adam Siwoń
Re: Typy generyczne
#345520
Author: Roman Tyczka
Date: Thu, 05 Jan 2017 14:27
19 lines
1281 bytes
On Thu, 5 Jan 2017 06:00:13 -0800 (PST), konsul675@gmail.com wrote:

> for i := 0 to main.listaDoc.Count-1 do
>     begin
> 
> 
>       result:=result+listaDoc.items[i];
>     end;
> 
> ewentualnie jak to zrobić?

Tak jak podał Ci Adam.
Gdyż Dictionary nie ma indeksu, kolejność jest przypadkowa (konkretnie
zależy od funkcji haszującej). Jeśli zależy Ci na kolejności to użyj
dictionary springowego i Ordered z customowym comparerem.

-- 
pozdrawiam
Roman Tyczka
Re: Typy generyczne
#345518
Author: konsul675
Date: Thu, 05 Jan 2017 14:31
2 lines
1310 bytes
Taj\k o te rozwiązanie chodziło dziękuje.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads