Help with SimpleGraph

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Help with SimpleGraph

Postby FoFyGa » September 3rd, 2011, 3:39 pm

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
FoFyGa
Active Member
Active Member
 
Posts: 8
Joined: September 3rd, 2011, 3:36 pm

Re: Help with SimpleGraph

Postby Kambiz » September 8th, 2011, 12:54 pm

sorry, but I didn't get the question.
Could you please explain it more in your own language?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Help with SimpleGraph

Postby FoFyGa » September 9th, 2011, 12:24 pm

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

Re: Help with SimpleGraph

Postby Kambiz » September 10th, 2011, 2:47 pm

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.');
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Help with SimpleGraph

Postby FoFyGa » September 10th, 2011, 8:15 pm

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-K12BPA

Original:
"Спасибо за ответ и помощь.
Нужно взять текст ссылки (ребра) между узлами. Узлы идентифицируются по подписи. Если узлы не связаны ничего делать не нужно.
Если вам не трудно помогите пожалуйста. Я уже давно мучаюсь над этим вопросом и не знаю как обратиться к ссылке.

Посмотрите пожалуйста вот это видео. На нём отображено то что мне необходимо сделать."
FoFyGa
Active Member
Active Member
 
Posts: 8
Joined: September 3rd, 2011, 3:36 pm

Re: Help with SimpleGraph

Postby Kambiz » September 11th, 2011, 1:09 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Help with SimpleGraph

Postby FoFyGa » September 11th, 2011, 5:53 pm

Undeclared identifier Source

and

Undeclared identifier Target
FoFyGa
Active Member
Active Member
 
Posts: 8
Joined: September 3rd, 2011, 3:36 pm

Re: Help with SimpleGraph

Postby Kambiz » September 11th, 2011, 8:03 pm

I've already compiled and tested this function on Delphi 7.
Apparently your compiler has problem with 'with' statement.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Help with SimpleGraph

Postby FoFyGa » September 12th, 2011, 3:57 am

But they are nowhere to be described

"Но они же нигде не описаны"
FoFyGa
Active Member
Active Member
 
Posts: 8
Joined: September 3rd, 2011, 3:36 pm

Re: Help with SimpleGraph

Postby Kambiz » September 12th, 2011, 7:02 am

Source and Target are properties of TGraphLink.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Help with SimpleGraph

Postby FoFyGa » September 12th, 2011, 1:20 pm

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" и ничего не нашел"
FoFyGa
Active Member
Active Member
 
Posts: 8
Joined: September 3rd, 2011, 3:36 pm

Re: Help with SimpleGraph

Postby Kambiz » September 12th, 2011, 2:04 pm

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. :)
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Help with SimpleGraph

Postby FoFyGa » September 12th, 2011, 2:14 pm

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

"Проблема в том что в новой версии можно создавать ссылку не только от узла но и где угодно. А мне необходимо чтобы ссылки создавались только между узлами"
FoFyGa
Active Member
Active Member
 
Posts: 8
Joined: September 3rd, 2011, 3:36 pm

Re: Help with SimpleGraph

Postby Kambiz » September 13th, 2011, 9:09 am

You can always use the appropriate events and link options to change the behavior.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Help with SimpleGraph

Postby FoFyGa » September 13th, 2011, 1:09 pm

I am not able to implement it. I did not do it. Thank you for your help.

"Я не в состоянии это реализовать. Я даже это не могу сделать. Спасибо вам за помощь."
FoFyGa
Active Member
Active Member
 
Posts: 8
Joined: September 3rd, 2011, 3:36 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron