Jump to content

Text size copy


B.Balemi

Recommended Posts

Any one know why this is returning this error .

not to sure why its invalid?

As you can see it doesnt take much to confuse me

Warning: TEXTCOPY HOBJECT1 - Handle to text object is not valid.

Warning: TEXTCOPY TEXTS - Handle to text object is not valid.

Var

px,py,px2,py2,texts:Real;

Hobject1,Hsymbol,Hobject2,Hsymbol2:Handle;

DummyVar,dummyvar2:Integer;

Begin

AlrtDialog('Pick text to copy');

WHILE Not GetPickObjectInfo(pX,pY,hObject1,hSymbol,dummyVar) DO BEGIN

GetPt(pX,pY);

texts:=GetTextSize(hobject1,1);

END;

AlrtDialog('Pick next text to change');

WHILE NOT GetPickObjectInfo(pX2,pY2,hObject2,hSymbol2,dummyVar2) DO BEGIN

GetPt(pX2,pY2);

SetTextSize(hobject2,1,100,texts);

END;

Cheers in advance

Brendan

Link to comment

Hi brendan,

I try your script, but I didn't get any error messages...? (try to restart your VW... could help). Anyways the text didn't resize... I know he should, and the NNA was kind giving the code for "While GetPickObjInfo... " : but that never work well for me, and I normally use a dummy boolean to use this function. Maybe somebody else have a better answer, but the modify code works well in my mac.

Hope that helps.

Regards.

code:

Procedure Brendan;

Var

px,py,px2,py2,texts:Real;

Hobject1,Hsymbol,Hobject2,Hsymbol2:Handle;

DummyVar,dummyvar2:Integer;

DummyV:BOOLEAN;

Begin

AlrtDialog('Pick text to copy');

GetPt(pX,pY);

DummyV:= GetPickObjectInfo(pX,pY,hObject1,hSymbol,dummyVar);

texts:=GetTextSize(hobject1,1);

AlrtDialog('Pick next text to change');

GetPt(pX2,pY2);

DummyV:=GetPickObjectInfo(pX2,pY2,hObject2,hSymbol2,dummyVar2);

SetTextSize(hobject2,1,100,texts);

END;

Run (Brendan);
[/code]

Link to comment

Brendan,

In both loops you are calling getpickobjectinfo first with px,py which have not yet been chosen by the user. You are then picking the coordinates which are used in the next getpickobjectinfo but before the next getpickobjectinfo is being called you are trying to get the text from a nil handle that allowed you in the loop in the first place.

The purpose of the while loop is to continue until you have picked an object. Once you have picked a valid object you then want to get the text from it. So your gettext statement should be after the loop. {You are kicked out if a valid object is found.} The same with the second loop. The settext should be after the loop.

Also you should not use the while not getpickobjectinfo deal unless you are sure there are no objects at 0,0 because it tests this first unless you initialize px,py to other numbers. This of course is unless you want to check there first.

You can fix this problem by putting a getpt(px,py) before each while loop. This way you can assure that every test case is one that the user chose.

Also I replaced

SetTextSize(hobject2,1,100,texts);

with

SetTextSize(hobject2,0,GetTextLength(hObject2),texts);

it's more accurate and changes the entire string.

here are my fixes to your code:

Procedure textcopy;

Var

px,py,px2,py2,texts:Real;

Hobject1,Hsymbol,Hobject2,Hsymbol2:Handle;

DummyVar,dummyvar2:Integer;

Begin

AlrtDialog('Pick text to copy');

GetPt(pX,pY);

WHILE Not GetPickObjectInfo(pX,pY,hObject1,hSymbol,dummyVar) DO BEGIN

GetPt(pX,pY);

END;

texts:=GetTextSize(hobject1,1);

AlrtDialog('Pick next text to change');

GetPt(pX2,pY2);

WHILE NOT GetPickObjectInfo(pX2,pY2,hObject2,hSymbol2,dummyVar2) DO BEGIN

GetPt(pX2,pY2);

END;

SetTextSize(hobject2,0,GetTextLength(hObject2),texts);

END;

run(textcopy);

Enjoy!

PS. Kiwi's modification works however if the user misses the object that they are trying to choose during the getpt operation the program won't let them choose again so the user will have to continue and then start over.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...