Einzelnen Beitrag anzeigen

Natcree

Registriert seit: 5. Mär 2013
502 Beiträge
 
Delphi 7 Enterprise
 
#4

AW: Strings zerlegen und in Button multiline.caption

  Alt 2. Jul 2014, 23:47
Hier mal der code mit dem es geht

Delphi-Quellcode:
Procedure BreakLongString (Const aString : String; aStringList : TStringList; aMaxLength : Integer);
Var
  X,X1, XEnd : Integer;
Begin
  X := 1;
  XEnd := Length (aString);
  While X < XEnd Do Begin
    X1 := Min (Xend, X+8);
    If X1<XEnd Then Begin
      While (X1>X) And (aString[X1]<>' ') Do Dec (X1);
      If X1 = X Then X1 := X + 8;
    End;
    aStringList.Add(Copy (aString,X,X1-X+1));
    X := X1+1;
  End
End;

function SetMultiLineCaption(const Button : TButton;const Caption : String;
const p_fAutoAdjust : Boolean = false) : Boolean;
begin
  Result := false;
  if SetWindowLong(Button.Handle, GWL_STYLE, GetWindowLong(Button.Handle, GWL_STYLE)
  or BS_MULTILINE)> 0 then
  begin
    Button.Caption := Caption;
    Result := true;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
ts:tstringlist;
i:integer;
begin
ts:=tstringlist.Create;
clientdataset1.RecNo:=1;
breaklongstring(Clientdataset1.FieldValues['Artikel'],ts,8);
i:=ts.Count;
if i=1 then
SetMultiLineCaption(button1,ts.Strings[0],true);
if i=2 then
SetMultiLineCaption(button1,ts.Strings[0]+#13#10+ts.Strings[1],true);
if i=3 then
SetMultiLineCaption(button1,ts.strings[0]+#13#10+ts.strings[1]+#13#10+ts.strings[2],true);
ts.Free;
end;
und hier der mit dem es nicht geht
Delphi-Quellcode:
Procedure BreakLongString (Const aString : String; aStringList : TStringList; aMaxLength : Integer);
Var
  X,X1, XEnd : Integer;
Begin
  X := 1;
  XEnd := Length (aString);
  While X < XEnd Do Begin
    X1 := Min (Xend, X+8);
    If X1<XEnd Then Begin
      While (X1>X) And (aString[X1]<>' ') Do Dec (X1);
      If X1 = X Then X1 := X + 8;
    End;
    aStringList.Add(Copy (aString,X,X1-X+1));
    X := X1+1;
  End
End;

function SetMultiLineCaption(const Button : TLMDDockspeedButton;const Caption : String;
const p_fAutoAdjust : Boolean = false) : Boolean;
begin
  Result := false;
  if SetWindowLong(Button.Control.Handle, GWL_STYLE, GetWindowLong(Button.Control.Handle, GWL_STYLE)
  or BS_MULTILINE)> 0 then
  begin
    Button.Caption := Caption;
    Result := true;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
ts:tstringlist;
i:integer;
begin
ts:=tstringlist.Create;
clientdataset1.RecNo:=1;
breaklongstring(Clientdataset1.FieldValues['Artikel'],ts,8);
i:=ts.Count;
if i=1 then
SetMultiLineCaption(LMDDockspeedbutton1,ts.Strings[0],true);
if i=2 then
SetMultiLineCaption(LMDDockspeedbutton1,ts.Strings[0]+#13#10+ts.Strings[1],true);
if i=3 then
SetMultiLineCaption(LMDDockspeedbutton1,ts.strings[0]+#13#10+ts.strings[1]+#13#10+ts.strings[2],true);
ts.Free;
end;
  Mit Zitat antworten Zitat