camaleonteplus (Normal User)
Pro
Messaggi: 95
Iscritto: 05/03/2009
|
Grazie a smanettone83 sono riuscito a realizzare questo codice:
Codice sorgente - presumibilmente Delphi |
procedure TRes.TrovaS2Click(Sender: TObject); var z,x,y: integer; S:STRING[10]; W, nDouble: Double; List: TStringList; maxValue,MinValue,distanza,attuale:single; begin VAL(Serie1.Caption,X,Z); nDouble := StrToFloatDef(ValRes.text, 0); nDouble := nDouble - X; STR(X,S); Label8.Caption := FormatFloat('#0.#', nDouble); MAxValue:= strtofloat(Label8.Caption); MinValue:=1; List:= Tstringlist.create; List.LoadFromFile(E.text+'.ini'); for x:=0 to list.Count-1 do begin application.ProcessMessages; distanza:= MaxValue - MinValue; Attuale:= MaxValue - strtofloat(list.strings[x]); if strtofloat(list.Strings[x]) = MaxValue then begin Serie2.Caption:= list.Strings[x]; exit; end; if (strtofloat(list.Strings[x]) < MaxValue) and (attuale < distanza) then begin Serie2.Caption:= list.Strings[x]; MinValue:= MaxValue - attuale; end; end; end;
|
ma adesso lo devo semplificare se avete visto nella prima parte effettua un calcolo per poi portare il valore in un label questo valore viene poi letto per essere cercato in un file e il risultato viene caricato in un label, come posso eliminare l'uso del primo label?
|
|
camaleonteplus (Normal User)
Pro
Messaggi: 95
Iscritto: 05/03/2009
|
Codice sorgente - presumibilmente Delphi |
procedure TRes.TrovaS2Click(Sender: TObject); var z,x,y: integer; S:STRING[10]; W, nDouble: Double; List: TStringList; maxValue,MinValue,distanza,attuale:single; begin VAL(Serie1.Caption,X,Z); nDouble := StrToFloatDef(ValRes.text, 0); nDouble := nDouble - X; STR(X,S); MAxValue:= (FormatFloat('#0.#', nDouble)); MinValue:=1; List:= Tstringlist.create; List.LoadFromFile(E.text+'.ini'); for x:=0 to list.Count-1 do begin application.ProcessMessages; distanza:= MaxValue - MinValue; Attuale:= MaxValue - strtofloat(list.strings[x]); if strtofloat(list.Strings[x]) = MaxValue then begin Serie2.Caption:= list.Strings[x]; exit; end; if (strtofloat(list.Strings[x]) < MaxValue) and (attuale < distanza) then begin Serie2.Caption:= list.Strings[x]; MinValue:= MaxValue - attuale; end; end; end;
|
Cosi non va bene mi dice:
[DCC Error] Res.pas(115): E2010 Incompatible types: 'Single' and 'string'
la riga è: MAxValue:= (FormatFloat('#0.#', nDouble));
|
|
smanettone83 (Normal User)
Pro
Messaggi: 124
Iscritto: 20/10/2010
|
Beh potresti semplicemente eliminare la label ed usare una variabile numerica ed usare quella se e' solo un problema di visualizzazione grafica...
|
|
camaleonteplus (Normal User)
Pro
Messaggi: 95
Iscritto: 05/03/2009
|
Postato originariamente da smanettone83:
Beh potresti semplicemente eliminare la label ed usare una variabile numerica ed usare quella se e' solo un problema di visualizzazione grafica...
|
Tipo cosi?
x := FormatFloat('#0.#', nDouble); |
|
smanettone83 (Normal User)
Pro
Messaggi: 124
Iscritto: 20/10/2010
|
La funzione FormatFloat restrituisce un valore string.... Se X è un integer ti basta usare INTTOSTR per convertirla
|
|
camaleonteplus (Normal User)
Pro
Messaggi: 95
Iscritto: 05/03/2009
|
Codice sorgente - presumibilmente Delphi |
procedure TRes.TrovaS2Click(Sender: TObject); var z,x,y: integer; S,C:STRING[10]; W, nDouble: Double; List: TStringList; maxValue,MinValue,distanza,attuale:single; begin VAL(Serie1.Caption,X,Z); nDouble := StrToFloatDef(ValRes.text, 0); nDouble := nDouble - X; STR(X,S); c:= (FormatFloat('#0.#', nDouble)); MAxValue:= c; MinValue:=1; List:= Tstringlist.create; List.LoadFromFile(E.text+'.ini'); for x:=0 to list.Count-1 do begin application.ProcessMessages; distanza:= MaxValue - MinValue; Attuale:= MaxValue - strtofloat(list.strings[x]); if strtofloat(list.Strings[x]) = MaxValue then begin Serie2.Caption:= list.Strings[x]; exit; end; if (strtofloat(list.Strings[x]) < MaxValue) and (attuale < distanza) then begin Serie2.Caption:= list.Strings[x]; MinValue:= MaxValue - attuale; end; end; end;
|
Mi da questo errore:
[DCC Error] Res.pas(115): E2010 Incompatible types: 'Single' and 'ShortString'
su questa riga:
MAxValue:= c;
Ultima modifica effettuata da camaleonteplus il 30/04/2013 alle 21:11 |
|
smanettone83 (Normal User)
Pro
Messaggi: 124
Iscritto: 20/10/2010
|
è normale perche C è una variabile string.
Prova con
maxvalue:= strtofloat(c);
|
|
camaleonteplus (Normal User)
Pro
Messaggi: 95
Iscritto: 05/03/2009
|
va bene! Grazie.
|
|
camaleonteplus (Normal User)
Pro
Messaggi: 95
Iscritto: 05/03/2009
|
con il programma da me realizzato posso visualizzare solo i numeri che cominciano con 1 ma vorrei andare al di sottto come posso fare? ho modificato MinValue:=1; in MinValue:=0.1; ma non va mi da un errore.
|
|