Форум: "Начинающим";
Текущий архив: 2008.03.02;
Скачать: [xml.tar.bz2];
ВнизTreeNode Найти похожие ветки
← →
Первокласник Вася (2008-02-08 12:43) [0]Привет!
Хочу попытаться написать прогу нападобие DelphiWorld.
Но не могу определиться со ссылками.
Сама структура имеется. Сохранена в файле. Есть также материалы - текстовые файлы.
Подскажите пожалуйста, как мне сохранить ссылки на эти файлы?
С уважением!
← →
Jeer © (2008-02-08 12:53) [1]Полное имя файла - есть строка.
← →
Первокласник Вася (2008-02-08 12:55) [2]А как же сохранить указатель (Data) на этот файл?
← →
Сергей М. © (2008-02-08 12:58) [3]
> как же сохранить указатель (Data)
Сохранять указатель в файле бессмысленно.
← →
Первокласник Вася (2008-02-08 13:00) [4]А как же тогда это реализовано?
Как же тогда открыть файл, выбрав соответствующий item?
← →
easy © (2008-02-08 13:01) [5]http://dfc.com.ru/?sid=2&id=7&itemid=1
← →
Первокласник Вася (2008-02-08 13:03) [6]Спасибо, тока ссылка что-то не работает :(
← →
easy © (2008-02-08 13:04) [7]
> ссылка что-то не работает
работает
← →
Первокласник Вася (2008-02-08 13:09) [8]работает все, но эта не работает :(
Может покажете что-нить, а как дальше, думаю что сам разберусь.
← →
easy © (2008-02-08 13:11) [9]In article <3ba5b631_2@dnews>, Kiran wrote:
> Can some one help me out, on how to save a treeview with its data/node on
> to a file.
> Data is an object which can have its own save/load method.
Saving and loading a treeview with dataType
{: Callback procedure to save the data for a node into a stream
via the passed writer. }
TNodeSaveDataProc =
Procedure( writer: TWriter; data: Pointer );
{: Callback function to load the data for a node from a stream
via the passed reader. }
TNodeLoadDataProc =
Function( reader: TReader ): Pointer;
Procedure SaveTreeviewToStream( tv: TTreeview; S: TStream;
saveProc: TNodeSaveDataProc );
Var
writer: TWriter;
node: TTreeNode;
Begin
Assert( Assigned( tv ));
Assert( Assigned( S ));
Assert( Assigned( saveProc ));
writer:= TWriter.Create( S, 4096 );
try
node:= tv.Items[0];
writer.WriteListBegin;
While node <> nil Do Begin
writer.WriteInteger( node.level );
writer.WriteString( node.Text );
writer.WriteInteger( node.Imageindex );
saveProc( writer, node.data );
node:= node.GetNext;
End; { While }
writer.WriteListEnd;
writer.FlushBuffer;
finally
writer.Free;
end;
End; { SaveTreeviewToStream }
Procedure LoadTreeviewFromStream( tv: TTreeview; S: TStream;
loadProc: TNodeLoadDataProc );
Var
reader: TReader;
node: TTreenode;
level: Integer;
Begin
Assert( Assigned( tv ));
Assert( Assigned( S ));
Assert( Assigned( loadProc ));
tv.Items.BeginUpdate;
try
tv.Items.Clear;
reader:= TReader.Create( S, 4096 );
try
node:= nil;
reader.ReadListBegin;
While not Reader.EndOfList Do Begin
level := reader.ReadInteger;
If node = nil Then
// create root node, ignore its level
node:= tv.Items.Add( nil, "" )
Else Begin
If level = node.level Then
node := tv.Items.Add( node, "" )
Else If level > node.level Then
node := tv.Items.AddChild( node, "" )
Else Begin
While Assigned(node) and (level < node.level) Do
node := node.Parent;
node := tv.Items.Add( node, "" );
End; { Else }
End; { Else }
node.Text := Reader.ReadString;
node.ImageIndex := Reader.ReadInteger;
node.Data := loadProc( Reader );
End; { While }
reader.ReadListEnd;
finally
reader.Free;
end;
finally
tv.items.Endupdate;
end;
End; { LoadTreeviewFromStream }
The complete logic for saving/loading the data (e.g. objects) associated
to the nodes is external to the two routines above and implemented
by two callback routines you have to write and pass to the save/load
routines. These callbacks encapsulate the knowledge specific to the
object or data you need to save. If you want to save objects of a
particular class, and if the class has been designed well, the routines
may look like this:Procedure SaveMyObject( writer: TWriter; data: Pointer );
Begin
writer.Writeboolean( Assigned(data));
If Assigned(data) Then Begin
Assert( TObject(data) Is TMyObject );
TMyObject(data).Save( writer );
End;
End;
Function LoadMyObject( reader: TReader ): Pointer;
Var
obj: TMyObject;
Begin
If reader.Readboolean Then Begin
obj:= TMyObject.Create;
obj.Load( reader );
Result := obj;
End { If }
Else
Result := nil;
End;
This way the eventual work of storing or loading the objects data
ends up where it belongs: with the object itself. The Save and Load
methods are ones you have to write yourself, of course.
Peter Below (TeamB) 100113.1101@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I"m unable to visit the newsgroups every day at the moment,
so be patient if you don"t get a reply immediately.
← →
Первокласник Вася (2008-02-08 13:14) [10]Большое спасибо!
Указали-подсказали куда да как копать! Спасибо ещё раз!
ща изучать код буду и экспериментировать :))))
Страницы: 1 вся ветка
Форум: "Начинающим";
Текущий архив: 2008.03.02;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.038 c