3

I need a small example on Delphi 5 on how the text of the items present in a radiogroup to wrap text if needed.

I resolved it in Delphi 2006 by accessing buttons property, but in D5 this property does not exist.

LE: is there any solution except than SetWindowLong ?

RBA
  • 12,337
  • 16
  • 79
  • 126

2 Answers2

3

You can get the buttons easily enough in Delphi 5 by iterating over the Controls property of the radio group. But then what are you going to do to make them wrap? The Delphi 5 radio button does not have a WordWrap property.

If I were you I would add a bunch of radio buttons to a group box rather than use a radio group. This gives you control over exactly what class of radio button you create. Then derive your own radio button class and implement the WordWrap property. To do this you need to add the BS_MULTILINE style in CreateParams, just as modern Delphi versions do.

Of course, the method outlined in your answer would work too!

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • By the way, I had not see your answer when I wrote mine. I was busy exploring my old Delphi versions!! – David Heffernan Nov 23 '11 at 17:12
  • The indications on how to do it are very useful. I post the question, and after that wrote the code. anyway, you were extremely quick! – RBA Nov 23 '11 at 17:23
2

done.

procedure TForm1.Button1Click(Sender: TObject);
var
 i: Integer;
 rbs: DWORD;
 rb: TRadioButton;
begin
 with RadioGroup1 do
 begin
  for i := 0 to ControlCount-1 do
   begin
    rb := radiogroup1.controls[i] as TRadioButton;
    rbs := GetWindowLong(rb.Handle, GWL_STYLE);
    rbs := rbs or BS_MULTILINE or BS_TOP;
    SetWindowLong(rb.Handle, GWL_STYLE, rbs);
   end ;
   Invalidate;
 end ;
end;
RBA
  • 12,337
  • 16
  • 79
  • 126