Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Help! Wordwrap in DelphiX?

  1. #1

    Help! Wordwrap in DelphiX?

    Daygreet. I decided to lurk even less and post a question. Hope this is the right section. My question is:

    Is there a relatively painless way of printing out large chunks of text to the screen, using DelphiX? I'm using Delphi 7, not sure what version of DelphiX I have...

    Up till now I've been using TextOut but I'd like something that lets me wordWrap. Any advice anyone can give me will be appreciated.
    Apologies in advance if this is a stupid question. I tried searching but didn't find any answers I liked. >_<
    *blink*

  2. #2

    Re: Help! Wordwrap in DelphiX?

    Try searching a while back on the forums here. There was a large topic about word wrapping
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3

    Re: Help! Wordwrap in DelphiX?

    TextOut is what you have to use, no way around. It is slightly more tricky to do if you want to cut from spaces but this is roughly how you can do it by cutting everything:
    [pascal]var
    i,charW,charH: integer;
    cur,position: TPoint;
    text: string; // This you can read from TStringList.Text or anything
    line: string;
    //maxWrapWidth: integer; // How wide the text can be before wrap
    begin
    with SomeOfYourSurfaces.Canvas do begin
    position:=Point(3,3); // This is upper corner of printed text
    cur:=Point(0,0);
    line:='';
    charH:=TextHeight('I'); // or you can manually type any row height
    for i:=1 to length(text) do begin
    charW:=TextWidth(text[i]);
    if cur.X+charW>maxWrapWidth then begin
    TextOut(position.X, position.Y+cur.Y, line);
    cur.X:=0;
    cur.Y:=cur.Y+charH;
    line:=text[i];
    end else begin
    cur.X:=cur.X+charW;
    line:=line+text[i];
    end;
    end;
    TextOut(position.X, position.Y+cur.Y, line);
    Release; // Needed with DelphiX surface, not with normal canvas
    end;
    end;[/pascal]
    Hope i didn't forget anything

  4. #4

    Re: Help! Wordwrap in DelphiX?

    Ah, thanks. That works.

    I wrote a similar wrapper in another project, but I was worried about speed. Should be fine tho. Good to know I'm not doing anything wrong by using TextOut.

    Thanks again.
    *blink*

  5. #5
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: Help! Wordwrap in DelphiX?

    When it comes to software there is no wrong, only some techniques are more right than others.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #6

    Re: Help! Wordwrap in DelphiX?

    Quote Originally Posted by WILL
    When it comes to software there is no wrong, only some techniques are more right than others.
    Sorry but I have to adress this

    Though I do get what you're trying to say it's wrong to say that there is no wrong in software. A trivial example would be a calculator program that gives you the wrong answer when you're solving the equation 2+2. A less transparent (and more serious) error would be an algorithm using floating points but not accounting for precision errors. Results can suddenly become totally wrong even though your algorithm is mathematically correct.

    But I agree that if a solution works in your context, there's no reason to improve it until you need to improve it.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  7. #7
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: Help! Wordwrap in DelphiX?

    Well sure you can always do something wrong. lol I've had my share. But if it is working then you could consider it right. Until you instead find a more right way of doing the same job, but better.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  8. #8

    Re: Help! Wordwrap in DelphiX?

    I'm gonna need to do better version of this for my UI Editor's memo component. What is still needed is character checks to not print characters under #32, #13 to force a line change and #32 to make a "delayed line change" which i thought of using another temp string for current line.

    Edit: Actually... there may be some automatic kind of wrapping on TStringList, in addition to already premade lines. So it should be easier than what i wrote above.

  9. #9

    Re: Help! Wordwrap in DelphiX?

    Ah, really? Let me know how it goes.
    *blink*

  10. #10

    Re: Help! Wordwrap in DelphiX?

    If you are going to make a unit to print text to screen then I suggest having it also handle text effects, like changing colour.

    We made a nice unit at work that can print paragraphs to the screen you can set the width of the paragraph so that it wraps at a given point, you can also set bold and italic etc. Don't use delphix much anymore except to maintain older software.
    The views expressed on this programme are bloody good ones. - Fred Dagg

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •