Page 1 of 1
Help with SimpleGraph

Posted:
September 3rd, 2011, 3:39 pm
by FoFyGa
Hello everyone. I do not speak English. But use your component SimpleGraph. Very good component but I can not solve one problem. I have Stringrid. All nodes are numbered in the order (via text). At the touch of a button or event I need to do the following:
to touch the top two edges of the text and put them in the appropriate cell stringrid.
For example take the node with the text "1" and the text "2" in cell 1-2 stringrid need to place text links connecting these nodes.
How to implement it?
Thanks in advance.
Component version v1.542
Sorry for the translation - translate translator google.ru
Re: Help with SimpleGraph

Posted:
September 8th, 2011, 12:54 pm
by Kambiz
sorry, but I didn't get the question.
Could you please explain it more in your own language?
Re: Help with SimpleGraph

Posted:
September 9th, 2011, 12:24 pm
by FoFyGa
Here is the text of my question in their native language:
"Привет всем. Я не говорю по английски. Но использую ваш компонент SimpleGraph. Очень хороший компонент но не могу решить одну задачу. У меня есть Stringrid. Все узлы пронумерованы по порядку(через текст). По нажатию на кнопку либо событию мне необходимо сделать следующее:
перебирать вершины по две и текст ребра заносить в соответствующую ячейку stringrid.
Например беру узел с текстом "1" и с текстом "2" и в ячейку 1-2 stringrid должен занести текст ссылки соединяющей эти узлы.
Как это реализовать?
Заранее благодарен."
Тоесть мне нужно перебрать все узлы, и заполнить компонент stringrid. Если узел не имеет текста, то в ячейку ничего не нужно заносить.
Original in Russian
Re: Help with SimpleGraph

Posted:
September 10th, 2011, 2:47 pm
by Kambiz
If I am right, you need to link two nodes identified by their captions.
Here is a function to do it:
- Code: Select all
function LinkNodesByText(SG: TSimpleGraph;
const NodeText1, NodeText2: String): TGraphLink;
var
Node1, Node2: TGraphNode;
I: Integer;
begin
Result := nil;
Node1 := nil; Node2 := nil;
for I := 0 to SG.Objects.Count - 1 do
if SG.Objects[I] is TGraphNode then
begin
if (Node1 = nil) and (SG.Objects[I].Text = NodeText1) then
begin
Node1 := TGraphNode(SG.Objects[I]);
if Node2 <> nil then
Break;
end
else if (Node2 = nil) and (SG.Objects[I].Text = NodeText2) then
begin
Node2 := TGraphNode(SG.Objects[I]);
if Node1 <> nil then
Break;
end
end;
if (Node1 <> nil) and (Node2 <> nil) then
Result := TGraphLink.CreateNew(SG, Node1, [], Node2);
end;
Usage:
- Code: Select all
var NewLink: TGraphLink;
NewLink := LinkNodesByText(SimpleGraph1, '1', '2');
if NewLink = nil then
ShowMessage('Error: Identified nodes could not be found.');
Re: Help with SimpleGraph

Posted:
September 10th, 2011, 8:15 pm
by FoFyGa
Thank you for your response and assistance.
We must take the text links (edges) between nodes. Nodes are identified by their captions. If the nodes are not linked do not need to do.
If you are not hard to please help. I had been tormented over this issue and I do not know how to access the link.
Look please here is the video. It displays what I need to do.
Link(youtube):
http://www.youtube.com/watch?v=-0nu-K12BPAOriginal:
"Спасибо за ответ и помощь.
Нужно взять текст ссылки (ребра) между узлами. Узлы идентифицируются по подписи. Если узлы не связаны ничего делать не нужно.
Если вам не трудно помогите пожалуйста. Я уже давно мучаюсь над этим вопросом и не знаю как обратиться к ссылке.
Посмотрите пожалуйста вот это видео. На нём отображено то что мне необходимо сделать."
Re: Help with SimpleGraph

Posted:
September 11th, 2011, 1:09 pm
by Kambiz
I modified the function to check for existence of the link. So, if the link already exists, it returns the link; otherwise, it establishes a new link between the nodes and return it.
- Code: Select all
function LinkNodesByText(SG: TSimpleGraph;
const NodeText1, NodeText2: String): TGraphLink;
var
Node1, Node2: TGraphNode;
I: Integer;
begin
Result := nil;
Node1 := nil; Node2 := nil;
// Find the nodes identified by the specified text strings
for I := 0 to SG.Objects.Count - 1 do
if SG.Objects[I] is TGraphNode then
begin
if (Node1 = nil) and (SG.Objects[I].Text = NodeText1) then
begin
Node1 := TGraphNode(SG.Objects[I]);
if Node2 <> nil then
Break;
end
else if (Node2 = nil) and (SG.Objects[I].Text = NodeText2) then
begin
Node2 := TGraphNode(SG.Objects[I]);
if Node1 <> nil then
Break;
end
end;
// If both nodes are found
if (Node1 <> nil) and (Node2 <> nil) then
begin
// Find the link between the nodes
for I := 0 to SG.Objects.Count - 1 do
if SG.Objects[I] is TGraphLink then
with TGraphLink(SG.Objects[I]) do
begin
if ((Source = Node1) and (Target = Node2)) or
((Source = Node2) and (Target = Node1)) then
begin
Result := TGraphLink(SG.Objects[I]);
Break;
end;
end;
// If the link does not exist, create it
if Result = nil then
Result := TGraphLink.CreateNew(SG, Node1, [], Node2);
end;
end;
By the way, nice video.
Re: Help with SimpleGraph

Posted:
September 11th, 2011, 5:53 pm
by FoFyGa
Undeclared identifier Source
and
Undeclared identifier Target
Re: Help with SimpleGraph

Posted:
September 11th, 2011, 8:03 pm
by Kambiz
I've already compiled and tested this function on Delphi 7.
Apparently your compiler has problem with 'with' statement.
Re: Help with SimpleGraph

Posted:
September 12th, 2011, 3:57 am
by FoFyGa
But they are nowhere to be described
"Но они же нигде не описаны"
Re: Help with SimpleGraph

Posted:
September 12th, 2011, 7:02 am
by Kambiz
Source and Target are properties of TGraphLink.
Re: Help with SimpleGraph

Posted:
September 12th, 2011, 1:20 pm
by FoFyGa
Maybe it's because that I have an old version of the component (v1.542)? I entered in the search for component "Source" and "Target" and found nothing
"Может это потомучто у меня старая версия компонента (v1.542)? Я вводил в поиск по компоненту "Source" и "Target" и ничего не нашел"
Re: Help with SimpleGraph

Posted:
September 12th, 2011, 2:04 pm
by Kambiz
I didn't know such an old version is still in use.
Upgrade to the latest version and make the life a bit easier for yourself.

Re: Help with SimpleGraph

Posted:
September 12th, 2011, 2:14 pm
by FoFyGa
The problem is that the new version, you can create a link, not only from the site and elsewhere. And I need to set up links only between nodes
"Проблема в том что в новой версии можно создавать ссылку не только от узла но и где угодно. А мне необходимо чтобы ссылки создавались только между узлами"
Re: Help with SimpleGraph

Posted:
September 13th, 2011, 9:09 am
by Kambiz
You can always use the appropriate events and link options to change the behavior.
Re: Help with SimpleGraph

Posted:
September 13th, 2011, 1:09 pm
by FoFyGa
I am not able to implement it. I did not do it. Thank you for your help.
"Я не в состоянии это реализовать. Я даже это не могу сделать. Спасибо вам за помощь."