Hallo Ich möchte in einem Clientdataset einen Artikel Eingeben und abspeichern.
Nun möchte ich einen Button diesen Artikelnamen als Caption Übergeben.Es normal über eine Tstringlist laufen lassen geht ohne Probleme sobald ich aber das Clientdataset1 als Quelle nutzen will gibt es Fehlermeldungen.
Procedure BreakLongString (Const aString : String; aStringList : TStringList; aMaxLength : Integer); Var
X,X1, XEnd : Integer; Begin
X := 1;
XEnd := Length (aString); While X < XEnd DoBegin
X1 := Min (Xend, X+8); If X1<XEnd ThenBegin 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 p_Button : TButton;const p_sCaption : String; const p_fAutoAdjust : Boolean = false) : Boolean; begin
Result := false; if SetWindowLong(p_Button.Handle, GWL_STYLE, GetWindowLong(p_Button.Handle, GWL_STYLE) or BS_MULTILINE)> 0 then begin
p_Button.Caption := p_sCaption;
Result := true; end; end;
procedure TForm1.Button1Click(Sender: TObject); var
ts:tstringlist;
i:integer; begin
ts:=tstringlist.Create;
breaklongstring(edit1.Text,ts,8);
i:=ts.Count; if i=1 then
SetMultiLineCaption(self.Button1,ts.Strings[0],true); if i=2 then
SetMultiLineCaption(self.Button1,ts.Strings[0]+#13#10+ts.Strings[1],true); if i=3 then
SetMultiLineCaption(self.Button1,ts.strings[0]+#13#10+ts.strings[1]+#13#10+ts.strings[2],true);
ts.Free; end;
Procedure BreakLongString (Const aString : String; aStringList : TStringList; aMaxLength : Integer); Var
X,X1, XEnd : Integer; Begin
X := 1;
XEnd := Length (aString); While X < XEnd DoBegin
X1 := Min (Xend, X+8); If X1<XEnd ThenBegin 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 p_Button : TButton;const p_sCaption : String; const p_fAutoAdjust : Boolean = false) : Boolean; begin
Result := false; if SetWindowLong(p_Button.Handle, GWL_STYLE, GetWindowLong(p_Button.Handle, GWL_STYLE) or BS_MULTILINE)> 0 then begin
p_Button.Caption := p_sCaption;
Result := true; end; end;
procedure TForm1.Button1Click(Sender: TObject); var
ts:Tstringlist;
j:integer; begin
ts:=tstringlist.Create;
form1.clientdataset1.recno:=1;
breaklongstring(form1.ClientDataSet1.FieldValues['Warengruppe'],ts,8);
j:=ts.Count; if j=1 then
SetMultiLineCaption(form1.LMDDockspeedbutton1,ts.Strings[0],true); if j=2 then
SetMultiLineCaption(form1.LMDDockspeedbutton1,ts.Strings[0]+#13#10+ts.Strings[1],true); if j=3 then
SetMultiLineCaption(form1.LMDDockspeedbutton1,ts.strings[0]+#13#10+ts.strings[1]+#13#10+ts.strings[2],true);
ts.Free; end;
j:=ts.Count; if j=1 then
SetMultiLineCaption( form1.LMDDockspeedbutton1, ts.Strings[0], true ); if j=2 then
SetMultiLineCaption( form1.LMDDockspeedbutton1, ts.Strings[0]+#13#10+ts.Strings[1], true ); if j=3 then
SetMultiLineCaption( form1.LMDDockspeedbutton1, ts.strings[0]+#13#10+ts.strings[1]+#13#10+ts.strings[2], true );
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
AW: Strings zerlegen und in Button multiline.caption
2. Jul 2014, 23:44
Habe es jetzt mit einem Standard TButton versucht und es klappt. Wenn ich in der function setmultiline
den TButton mit meinem TLMDDockspeedbutton austausche muss ich auch statt button.handle auf Button.control.handle umstellen sonst bleibt handle undeclared.
Sieht er so aus als ob die LMD Komponente nicht mit diesem Code klar kommt. Was kann ich da noch machen?
Procedure BreakLongString (Const aString : String; aStringList : TStringList; aMaxLength : Integer); Var
X,X1, XEnd : Integer; Begin
X := 1;
XEnd := Length (aString); While X < XEnd DoBegin
X1 := Min (Xend, X+8); If X1<XEnd ThenBegin 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;
Procedure BreakLongString (Const aString : String; aStringList : TStringList; aMaxLength : Integer); Var
X,X1, XEnd : Integer; Begin
X := 1;
XEnd := Length (aString); While X < XEnd DoBegin
X1 := Min (Xend, X+8); If X1<XEnd ThenBegin 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;
AW: Strings zerlegen und in Button multiline.caption
2. Jul 2014, 23:49
Und du bist dir sicher, dass form1
auch initialisiert ist? form1.LMDDockspeedbutton1
Im Code vorher nimmst du noch self
(besser), aber warum lässt du das nicht einfach weg und investierst die gesparte Tippzeit in eine ordentliche Formatierung?
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
Ja es läuft auch. Kann es sein die findet eine pas datei nicht. kann es daran liegen das ich nur ne trial von den LMD Compos installiert habe?
Nö, die packen auch bei den Trials den gesamten Source-Code dabei. Falls du doch nicht kaufst, kannst du problemlos die Stellen aus dem Source nehmen, die die Trial zu einer Trial macht
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)