|
List Info
Thread: Working with ExtTextOut
|
|
| Working with ExtTextOut |
  United States |
2008-03-18 14:19:05 |
|
Hello!
I am trying to implement some code I got to center text in a String Grid
cell. The original code was way too complex for my work so I simplified
it but I am missing something with the ExtTextOut Win32 Function. Here
is my code:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
Integer;
Rect: TRect; State: TGridDrawState);
var
DY: Integer;
Text: string;
S: array[0..255] of Char;
Const ARect: = Rect; <--------Problem here
Begin
Rect := ARect;
DY := 2;
Text := StringGrid1.Cells[Acol,ARow];
with StringGrid1.Canvas do
Begin X
ExtTextOut(Handle,
// HDC
Rect.Left + (Rect.Right - Rect.Left -
TextWidth(Text)) div 2, // X Position
Top + DY,
// YPosition
ETO_OPAQUE or ETO_CLIPPED,
// Text output options
ARect,
// Constant TRect type
StrPCopy(S, Text),
// Pointer to String
Length(Text),
// Length of String
nil);
// Pointer to intercharacter spacing
end;
end;
According to the help text, ARect needs to be a constant. However I
cannot format the Constant in the upper section.
Can anyone help here?
Thanks in advance!
Tom Nesler
[Non-text portions of this message have been removed]
__._,_.___
.
__,_._,___
|
| Re: Working with ExtTextOut |
  United States |
2008-03-18 14:35:04 |
O/H Nesler, Thomas J έγραψε:
>
>
> Hello!
>
> I am trying to implement some code I got to center text
in a String Grid
> cell. The original code was way too complex for my work
so I simplified
> it but I am missing something with the ExtTextOut Win32
Function. Here
> is my code:
>
> procedure TForm1.StringGrid1DrawCell(Sender: TObject;
ACol, ARow:
> Integer;
> Rect: TRect; State: TGridDrawState);
> var
> DY: Integer;
> Text: string;
> S: array[0..255] of Char;
> Const ARect: = Rect; <--------Problem here
>
> Begin
> Rect := ARect;
> DY := 2;
> Text := StringGrid1.Cells[Acol,ARow];
> with StringGrid1.Canvas do
> Begin X
> ExtTextOut(Handle,
> // HDC
> Rect.Left + (Rect.Right - Rect.Left -
> TextWidth(Text)) div 2, // X Position
> Top + DY,
> // YPosition
> ETO_OPAQUE or ETO_CLIPPED,
> // Text output options
> ARect,
> // Constant TRect type
> StrPCopy(S, Text),
> // Pointer to String
> Length(Text),
> // Length of String
> nil);
> // Pointer to intercharacter spacing
> end;
> end;
>
> According to the help text, ARect needs to be a
constant. However I
> cannot format the Constant in the upper section.
>
> Can anyone help here?
>
> Thanks in advance!
>
> Tom Nesler
>
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol,
ARow:Integer; Rect: TRect; State: TGridDrawState);
var
DY : Integer;
Text : string;
Begin
DY := 2;
Text := StringGrid1.Cells[Acol,ARow];
ExtTextOut(StringGrid1.Canvas.Handle,
Rect.Left + (Rect.Right - Rect.Left -
TextWidth(Text)) div 2,
Top + DY,
Rect,
PChar(Text),
Length(Text),
nil);
end;
--
Regards
Theo
------------------------
Theo Bebekis
Thessaloniki, Greece
------------------------
Greek_Delphi_Prog : a Delphi Programming mailing list in
Greek at
http:
//groups.yahoo.com/group/Greek_Delphi_Prog
CSharpDotNetGreek : A C# and .Net mailing list in Greek
language at
http:
//groups.yahoo.com/group/CSharpDotNetGreek
atla_custom : a Unisoft Atlantis Customization mailing list
at
http://grou
ps.yahoo.com/group/atla_custom
------------------------
------------------------------------
-----------------------------------------------------
Home page: http://group
s.yahoo.com/group/delphi-en/
To unsubscribe: delphi-en-unsubscribe@yahoogroups.comYahoo!
Groups Links
<*> To visit your group on the web, go to:
http://group
s.yahoo.com/group/delphi-en/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://g
roups.yahoo.com/group/delphi-en/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:delphi-en-digest@yahoogroups.com
mailto:delphi-en-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
delphi-en-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|
|
| Re: Working with ExtTextOut |
  United States |
2008-03-18 20:06:46 |
|
Nesler, Thomas J wrote:
> I am trying to implement some code I got to center text in a String Grid
> cell. The original code was way too complex for my work so I simplified
> it but I am missing something with the ExtTextOut Win32 Function.
Did the original code work?
> Here is my code:
>
> procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
> Integer;
> Rect: TRect; State: TGridDrawState);
> var
> DY: Integer;
> Text: string;
> S: array[0..255] of Char;
> Const ARect: = Rect; <--------Problem here
Well, of course there's a problem. That won't even compile. First, a
colon can never be followed by an equals sign in a const declaration;
there needs to be a type in between. Second, " Rect" is not a constant
expression.
> Begin
> Rect := ARect;
You're overwriting the rectangle you've been told to draw in with a
pointer to something that hasn't been initialized to anything sensible.
> DY := 2;
> Text := StringGrid1.Cells[Acol,ARow];
> with StringGrid1.Canvas do
> Begin X
There seems to be a stray X on that line.
> ExtTextOut(Handle,
> // HDC
> Rect.Left + (Rect.Right - Rect.Left -
> TextWidth(Text)) div 2, // X Position
> Top + DY,
Do you mean Rect.Top?
> // YPosition
> ETO_OPAQUE or ETO_CLIPPED,
> // Text output options
> ARect,
> // Constant TRect type
> StrPCopy(S, Text),
> // Pointer to String
Your code will crash in a fiery ball when the length of Text happens to
exceed 255 characters.
You don't need to pass a pointer to an array. A pointer to the first
character of S is fine. A pointer to a character is a pointer to a
character, no matter where that character lives. Simply pass PChar(Text).
> Length(Text),
> // Length of String
> nil);
> // Pointer to intercharacter spacing
> end;
> end;
>
> According to the help text, ARect needs to be a constant. However I
> cannot format the Constant in the upper section.
No, that's not what that means. "const foo*" means a pointer to a const
foo. In other words, when the receiver dereferences the pointer, what it
has is a foo that it's not allowed to modify. Whether the code that
provided the foo is allowed to modify it is a completely separate issue.
Pointers to non-const are always convertible implicitly to pointers to
const.
Delphi doesn't even have the notion of pointers to const, so you really
had no hope of reproducing the argument types in the C documentation.
--
Rob
__._,_.___
.
__,_._,___
|
| Re: Working with ExtTextOut |
  Poland |
2008-03-19 05:24:29 |
|
Hello!
May be TStringAlignGrid 2.1 ( http://www.delphi32.com/vcl/4920/ ) solve
your problem.
Jarek
Nesler, Thomas J wrote:
>
> Hello!
>
> I am trying to implement some code I got to center text in a String Grid
> cell. The original code was way too complex for my work so I simplified
> it but I am missing something with the ExtTextOut Win32 Function. Here
> is my code:
>
> procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
> Integer;
> Rect: TRect; State: TGridDrawState);
> var
> DY: Integer;
> Text: string;
> S: array[0..255] of Char;
> Const ARect: = Rect; <--------Problem here
>
> Begin
> Rect := ARect;
> DY := 2;
> Text := StringGrid1.Cells[Acol,ARow];
> with StringGrid1.Canvas do
> Begin X
> ExtTextOut(Handle,
> // HDC
> Rect.Left + (Rect.Right - Rect.Left -
> TextWidth(Text)) div 2, // X Position
> Top + DY,
> // YPosition
> ETO_OPAQUE or ETO_CLIPPED,
> // Text output options
> ARect,
> // Constant TRect type
> StrPCopy(S, Text),
> // Pointer to String
> Length(Text),
> // Length of String
> nil);
> // Pointer to intercharacter spacing
> end;
> end;
>
> According to the help text, ARect needs to be a constant. However I
> cannot format the Constant in the upper section.
>
> Can anyone help here?
>
> Thanks in advance!
>
> Tom Nesler
>
>
> [Non-text portions of this message have been removed]
>
>
>
> __________ NOD32 Informacje 2957 (20080318) __________
>
> Wiadomosc zostala sprawdzona przez System Antywirusowy NOD32
> http://www.nod32.com lub http://www.nod32.pl
__._,_.___
.
__,_._,___
|
[1-4]
|
|