TsimpleGraph 1.67 trick.

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

TsimpleGraph 1.67 trick.

Postby elias » March 8th, 2006, 3:43 pm

I missed in the v2.0 the posibility that i had in v1.67 to keep the conexion with original node when copying/pasting a link. It is a very interesing option, but it has a little problem:
If you have a node IDed 1 linked at a node IDed 2 via a link IDed 3; and you cut (Ctrl-X) Node IDed1 and Link IDed3, you keep the Node IDed 2 in the Graph and the others in the clipboard.
Now if you:
Paste: There's no problem, the Graph becomes like before.
Delete the Node and paste: There's no problem, The link is not useful and destroyed.
Delete the node, create a new node, and paste: The New node get IDed1, so the link conects to New node, yet it is the node you created at first!
Trick:
Change
Code: Select all
function TSimpleGraph.GetUniqueID(PreferredID: DWORD): DWORD;
var
  I: Integer;
  IsUnique: Boolean;
  CandidateID: DWORD;
begin
  CandidateID := PreferredID;
  repeat
    IsUnique := True;
    for I := Objects.Count - 1 downto 0 do
      if Objects[I].ID = CandidateID then
      begin
        IsUnique := False;
        Inc(CandidateID);
        Break;
      end;
  until IsUnique;
  Result := CandidateID;
end;

for
Code: Select all
function TSimpleGraph.GetUniqueID: TDateTime;
Begin;
  Result:=Now;
End;

And change all the references/declarations to IDs like DWORD for TDateTime type.

Each node will have an ID not integer, but double, and they always have different IDs, being this IDs them dates of birth too.

Any comments? Any different posibilities?
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Re: TsimpleGraph 1.67 trick.

Postby Adem » March 8th, 2006, 6:14 pm

elias wrote:And change all the references/declarations to IDs like DWORD for TDateTime type.

Each node will have an ID not integer, but double, and they always have different IDs, being this IDs them dates of birth too.

Any comments? Any different posibilities?


Hi,

I have no idea how to respond to the rest of your question, but this UniqueID thing should really be TGUID.

A GUID is the only thing that one can reliably consider to be sufficiently unique.

TDataTime or a DWORD will get to bite someone sometime (think of copy-pasting between 2 separate applications) and when you're creating nodes under program control which can be faster than TDateTime can handle.

You can use CreateGUID(), IsEqualGUID() and GUIDToString(), StringToGUID() stuff quite easily for the same purpose.
Adem
Active Member
Active Member
 
Posts: 22
Joined: February 20th, 2006, 12:47 pm

Postby Kambiz » March 8th, 2006, 9:55 pm

Time resolution is 1ms, which is mush less than processor speed. So, it's not guaranteed to generate a unique id.

GUID is a good choice, however we do not need a public unique id.

By the way, in v2.1 I've made major changes in this area.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby elias » March 9th, 2006, 10:23 am

I have not Idea about whats GUID. But if you say it's good, I'll do a research.
GUID Mmm...? I'll comment you what I get soon.
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby kokkoras » March 9th, 2006, 1:05 pm

elias wrote:I have not Idea about whats GUID.


Global Unique IDentifier ..or something like this

It's a unique id. It is used everywhere in XP (application identification), real life (credit card numbers), etc.
Fotis
User avatar
kokkoras
Moderator
Moderator
 
Posts: 317
Joined: March 12th, 2005, 11:19 pm
Location: Thessaloniki, Greece

Postby elias » March 9th, 2006, 1:11 pm

Found in Wikipedia:
A Globally Unique Identifier or GUID is a pseudo-random number used in software applications. While each generated GUID is not guaranteed to be unique, the total number of unique keys (2128 or 3.4028×1038) is so large that the possibility of the same number being generated twice is very small.


Ahaha! but the posibility exist... :)

However, I'll use such GUID
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby Adem » March 9th, 2006, 10:05 pm

elias wrote:Ahaha! but the posibility exist... :)


Glad to see someone who takes things seriously. :D

You can, however, rest assured that many generations of your offsprings will not see the same GUID generated twice. Here is an except from the link below it

This specification defines the format of UUIDs (Universally Unique IDentifiers), also known as GUIDs (Globally Unique IDentifiers). A UUID is 128 bits long, and if generated according to the one of the mechanisms in this document, is either guaranteed to be different from all other UUIDs/GUIDs generated until 3400 A.D. or extremely likely to be different (depending on the mechanism chosen).


http://www.the-gdf.org/wiki/index.php?title=Globally_Unique_Identifiers_and_Digital_Fingerprints[/b]
Adem
Active Member
Active Member
 
Posts: 22
Joined: February 20th, 2006, 12:47 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest