Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Freaky GroupBox caption problem

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
Hi, I'm having a really wierd problem wiht my GroupBox captions.

If I have code such as the following:

Code:
aPhrase := 'Second half';
grpWhatever.caption := Concat('Something - ' , aPhrase , ' ...');

Nothing after the variable shows in the caption, it's just cut off (this also happens using + between each part instead of using the concat function, so it's not a problem with that function).

If I do the following:

Code:
grpWhatever.caption := Concat('Something - ' , 'Second half' , ' ...');

It all works as expected. So my question, what's going on? I'm completely confused here as to why it fails.
 
I created a simple app to try and reproduce the problem you described. I was not successful. My guess is that you may not have enough visible space on the groupbox to show the remaining area. Here is a sample app.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
gbx: TGroupBox;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
gbx.Caption := Concat('Something + ' , 'Do something', ' ...Blah blah');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
aPh : string;
begin
aPh := 'Do Something';
gbx.Caption := Concat('Something + ', aPh, ' ...Blah blah');
end;

end.
 
FYI,

According to the documentation, using the plus(+) operator performs the same function as concat and is faster.
 
I don't think it's a space limitation, because if I type it to say exactly the same as it would do using the variable then it displays the whole string.

I've just tried it in a new app and it works exactly as it should. Strange. It still doesn't work in my app I'm working on using exactly the same code for that particular bit.
 
I'm an idiot. It suddenly occured to me that the string I'm putting in there is pulled from a file and is zero-terminated so the caption ends at that point. My problem now is how to stop it being zero-terminated.

Code such as:
Code:
copy(sectionName,1,length(sectionName)-1)

doesn't appear to work, I can set the length modifier ( -1 in the example ) to as much as I want and it still just spits out the whole string.
 
Lets say the text you are loading from the file is in FirstString. Try:

Code:
var
  WorkStr : AnsiString;
begin
  SetLength(WorkStr, Length(FirstStr);
  Move(FirstStr[1], WorkStr[1], Length(FirstStr));
end;


Not sure it will work as I've never seen the problem you are having... What Delphi version are you using?

buho (A).
 
Ah, another thought. The string is a set length, but the termination happens after the actual content, hence why pulling one off the size didn't work before. The string could be:

"STUFF# "

with the # denoting the terminating character.

I've fixed it though, came up with this:

Code:
i := 1;
done := false;

repeat
   if sectionName[i] <> chr(0) then
      tempStr := tempStr + sectionName[i]
   else
      done := true;
   inc(i);
until done;

there's probably a better way though.
 
I do things like
Code:
SetLength(ThisString, 1000);
//  call an API function that stuffs something in PChar(ThisString)
SetLength(ThisString, StrLen(PChar(ThisString)));

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top