|
|
Регистрация Восстановить пароль |
Повторная активизация e-mail |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
|
Опции темы | Поиск в этой теме |
26.07.2010, 19:04 | #1 |
Новичок
Джуниор
Регистрация: 26.07.2010
Сообщений: 2
|
Помогите сохранить бинарное дерево в файл!!!
Ребят помогите сохранить бинарное дерево в файл как рисунок)
чтобы при нажатии save в подменю все сохранялось) там все есть,ток с сохранением не могу разобраться... вот фрагмент кода..плюс еще в архиве лежит весь проект unit BinaryF; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Menus, BinaryC, StdCtrls,rename; type TBinaryForm = class(TForm) MainMenu1: TMainMenu; File1: TMenuItem; mnuExit: TMenuItem; Help1: TMenuItem; mnuAbout: TMenuItem; CmdAddLeft: TButton; CmdAddRight: TButton; CmdRemove: TButton; Open1: TMenuItem; Save1: TMenuItem; Button1: TButton; procedure mnuExitClick(Sender: TObject); procedure mnuAboutClick(Sender: TObject); procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormCreate(Sender: TObject); procedure FormPaint(Sender: TObject); procedure SetButtons; procedure SelectNode(new_selection : TBinaryNode); procedure CmdAddLeftClick(Sender: TObject); procedure CmdAddRightClick(Sender: TObject); procedure CmdRemoveClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var BinaryForm: TBinaryForm; implementation var root, selected : TBinaryNode; x0, y0, node_id : Integer; {$R *.DFM} procedure TBinaryForm.mnuExitClick(Sender: TObject); begin Close; end; procedure TBinaryForm.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin // Select the node at the given point. SelectNode( root.NodeAtPoint(X, Y)); end; // Create the root node. procedure TBinaryForm.FormCreate(Sender: TObject); var xmin : Integer; begin // Create a one node tree. root := TBinaryNode.Create; root.Id := 'Root'; node_id := 0; // Save the coordinates where we will start drawing. x0 := 3; y0 := CmdAddLeft.Top + CmdAddLeft.Height + 3; // Use bold text. Canvas.Font.Style := [fsBold]; // Position the initial one node tree. xmin := x0; root.SetPosition(xmin, y0); end; // Draw the tree. procedure TBinaryForm.FormPaint(Sender: TObject); var rect : TRect; begin // Erase the canvas. rect.Left := 0; rect.Right := Width; rect.Top := 0; rect.Bottom := Height; Canvas.Brush.Color := clLtGray; Canvas.FillRect(rect); // Draw the tree. root.DrawSubtree(Canvas, selected); end; // Enable the correct buttons for the selected node. procedure TBinaryForm.SetButtons; begin if (selected = nil) then begin CmdAddLeft.Enabled := False; CmdAddRight.Enabled := False; CmdRemove.Enabled := False; end else begin CmdAddLeft.Enabled := (selected.LeftChild = nil); CmdAddRight.Enabled := (selected.RightChild = nil); CmdRemove.Enabled := (selected <> root); end; end; procedure TBinaryForm.SelectNode(new_selectio n : TBinaryNode); begin // Unselect the previously selected node. if (selected <> nil) then selected.DrawNode(Canvas, nil); // Select the new node. selected := new_selection; // Highlight the selected node. if (selected <> nil) then selected.DrawNode(Canvas, selected); SetButtons; end; // Add a left child to the selected node. procedure TBinaryForm.CmdAddLeftClick(Sender: TObject); var xmin : Integer; begin node_id := node_id + 1; selected.LeftChild := TBinaryNode.Create; selected.LeftChild.Id := IntToStr(node_id); selected.LeftChild.ParentNode := selected; // Reposition the nodes. xmin := x0; root.SetPosition(xmin, y0); // Enable the correct buttons. SetButtons; Refresh; end; procedure TBinaryForm.CmdAddRightClick(Sender : TObject); var xmin : Integer; begin selected.RightChild := TBinaryNode.Create; selected.RightChild.Id := IntToStr(node_id); selected.RightChild.ParentNode := selected; // Reposition the nodes. xmin := x0; root.SetPosition(xmin, y0); // Enable the correct buttons. SetButtons; Refresh; end; // Remove the selected node and its descendants. procedure TBinaryForm.CmdRemoveClick(Sender: TObject); var xmin : Integer; target : TBinaryNode; begin // Unselect the node. target := selected; SelectNode(nil); // Remove the selected node from the tree. if (target = target.ParentNode.LeftChild) then target.ParentNode.LeftChild := nil else target.ParentNode.RightChild := nil; // Free the node and its descendants. target.Free; // Reposition the remaining nodes. xmin := x0; root.SetPosition(xmin, y0); Refresh; end; end. |
26.07.2010, 21:33 | #2 |
Форумчанин
Регистрация: 16.08.2008
Сообщений: 276
|
Для начала, есть теги [СODE][/СODE], которые обрамляют исходники...
А во вторых. Я правильно Вас понимаю: У Вас есть некое бинарное дерево, вы нажимаете на кнопочку Save и вуаля... ваше дерево сохранено как картинка, где листьями являются значения листьев бинарного дерева?
Искусственный интеллект - фигня по сравнению с естественной глупостью
|
26.07.2010, 21:40 | #3 |
Новичок
Джуниор
Регистрация: 26.07.2010
Сообщений: 2
|
ок) в след раз буду иметь ввиду))
да именно это я и хочу изобразить) |
26.07.2010, 22:08 | #4 |
Форумчанин
Регистрация: 16.08.2008
Сообщений: 276
|
На сколько я понимаю Вы рисуете дерево на форме, значит у Вас есть доступ к канве. Ну и сохраняйте канву куда Вам надо...
Вот я вам примерец набросал. Это самый простой пример, он не весьма быстрый, но действенный: Код:
Искусственный интеллект - фигня по сравнению с естественной глупостью
Последний раз редактировалось Impuls1989; 26.07.2010 в 22:19. |
Похожие темы | ||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
бинарное дерево записать в файл. | lubafffka | Общие вопросы C/C++ | 4 | 06.05.2009 15:47 |
бинарное дерево записать в файл | lubafffka | Помощь студентам | 1 | 05.05.2009 19:22 |
сохранить бинарное дерево в файле | lubafffka | Общие вопросы C/C++ | 1 | 30.04.2009 21:39 |
Бинарное дерево | lubafffka | Общие вопросы C/C++ | 0 | 29.04.2009 12:28 |