Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Delphi - (Delphi) Semplificare
Forum - Delphi - (Delphi) Semplificare

Avatar
camaleonteplus (Normal User)
Pro


Messaggi: 95
Iscritto: 05/03/2009

Segnala al moderatore
Postato alle 14:12
Martedì, 30/04/2013
Grazie a smanettone83 sono riuscito a realizzare questo codice:
Codice sorgente - presumibilmente Delphi

  1. procedure TRes.TrovaS2Click(Sender: TObject);
  2. var
  3. z,x,y: integer;
  4. S:STRING[10];
  5. W, nDouble: Double;
  6. List: TStringList;
  7. maxValue,MinValue,distanza,attuale:single;
  8. begin
  9. VAL(Serie1.Caption,X,Z);
  10.   nDouble := StrToFloatDef(ValRes.text, 0);
  11.   nDouble := nDouble - X;
  12.   STR(X,S);
  13.  Label8.Caption := FormatFloat('#0.#', nDouble);
  14. MAxValue:= strtofloat(Label8.Caption);
  15. MinValue:=1;
  16. List:= Tstringlist.create;
  17. List.LoadFromFile(E.text+'.ini');
  18.  for x:=0 to list.Count-1 do begin
  19.  application.ProcessMessages;
  20.   distanza:= MaxValue - MinValue;
  21.   Attuale:= MaxValue - strtofloat(list.strings[x]);
  22.   if strtofloat(list.Strings[x]) = MaxValue then begin
  23.   Serie2.Caption:= list.Strings[x];
  24.   exit;
  25.   end;
  26.   if (strtofloat(list.Strings[x]) < MaxValue) and (attuale < distanza) then begin
  27.   Serie2.Caption:= list.Strings[x];
  28.   MinValue:= MaxValue - attuale;
  29.  end;
  30. end;
  31. 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?

PM Quote
Avatar
camaleonteplus (Normal User)
Pro


Messaggi: 95
Iscritto: 05/03/2009

Segnala al moderatore
Postato alle 14:16
Martedì, 30/04/2013
Codice sorgente - presumibilmente Delphi

  1. procedure TRes.TrovaS2Click(Sender: TObject);
  2. var
  3. z,x,y: integer;
  4. S:STRING[10];
  5. W, nDouble: Double;
  6. List: TStringList;
  7. maxValue,MinValue,distanza,attuale:single;
  8. begin
  9. VAL(Serie1.Caption,X,Z);
  10.   nDouble := StrToFloatDef(ValRes.text, 0);
  11.   nDouble := nDouble - X;
  12.   STR(X,S);
  13. MAxValue:= (FormatFloat('#0.#', nDouble));
  14. MinValue:=1;
  15. List:= Tstringlist.create;
  16. List.LoadFromFile(E.text+'.ini');
  17.  for x:=0 to list.Count-1 do begin
  18.  application.ProcessMessages;
  19.   distanza:= MaxValue - MinValue;
  20.   Attuale:= MaxValue - strtofloat(list.strings[x]);
  21.   if strtofloat(list.Strings[x]) = MaxValue then begin
  22.   Serie2.Caption:= list.Strings[x];
  23.   exit;
  24.   end;
  25.   if (strtofloat(list.Strings[x]) < MaxValue) and (attuale < distanza) then begin
  26.   Serie2.Caption:= list.Strings[x];
  27.   MinValue:= MaxValue - attuale;
  28.  end;
  29. end;
  30. end;


Cosi non va bene mi dice:
[DCC Error] Res.pas(115): E2010 Incompatible types: 'Single' and 'string'
la riga è: MAxValue:= (FormatFloat('#0.#', nDouble));

PM Quote
Avatar
smanettone83 (Normal User)
Pro


Messaggi: 124
Iscritto: 20/10/2010

Segnala al moderatore
Postato alle 15:09
Martedì, 30/04/2013
Beh potresti semplicemente eliminare la label ed usare una variabile numerica ed usare quella se e' solo un problema di visualizzazione grafica...



PM Quote
Avatar
camaleonteplus (Normal User)
Pro


Messaggi: 95
Iscritto: 05/03/2009

Segnala al moderatore
Postato alle 15:21
Martedì, 30/04/2013
Testo quotato

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);

PM Quote
Avatar
smanettone83 (Normal User)
Pro


Messaggi: 124
Iscritto: 20/10/2010

Segnala al moderatore
Postato alle 20:40
Martedì, 30/04/2013
La funzione FormatFloat restrituisce un valore string.... Se X è un integer ti basta usare INTTOSTR per convertirla

PM Quote
Avatar
camaleonteplus (Normal User)
Pro


Messaggi: 95
Iscritto: 05/03/2009

Segnala al moderatore
Postato alle 21:03
Martedì, 30/04/2013
Codice sorgente - presumibilmente Delphi

  1. procedure TRes.TrovaS2Click(Sender: TObject);
  2. var
  3. z,x,y: integer;
  4. S,C:STRING[10];
  5. W, nDouble: Double;
  6. List: TStringList;
  7. maxValue,MinValue,distanza,attuale:single;
  8. begin
  9. VAL(Serie1.Caption,X,Z);
  10.   nDouble := StrToFloatDef(ValRes.text, 0);
  11.   nDouble := nDouble - X;
  12.   STR(X,S);
  13. c:= (FormatFloat('#0.#', nDouble));
  14. MAxValue:= c;
  15. MinValue:=1;
  16. List:= Tstringlist.create;
  17. List.LoadFromFile(E.text+'.ini');
  18.  for x:=0 to list.Count-1 do begin
  19.  application.ProcessMessages;
  20.   distanza:= MaxValue - MinValue;
  21.   Attuale:= MaxValue - strtofloat(list.strings[x]);
  22.   if strtofloat(list.Strings[x]) = MaxValue then begin
  23.   Serie2.Caption:= list.Strings[x];
  24.   exit;
  25.   end;
  26.   if (strtofloat(list.Strings[x]) < MaxValue) and (attuale < distanza) then begin
  27.   Serie2.Caption:= list.Strings[x];
  28.   MinValue:= MaxValue - attuale;
  29.  end;
  30. end;
  31. 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
PM Quote
Avatar
smanettone83 (Normal User)
Pro


Messaggi: 124
Iscritto: 20/10/2010

Segnala al moderatore
Postato alle 1:32
Mercoledì, 01/05/2013
è normale perche C è una variabile string.

Prova con

maxvalue:= strtofloat(c);

PM Quote
Avatar
camaleonteplus (Normal User)
Pro


Messaggi: 95
Iscritto: 05/03/2009

Segnala al moderatore
Postato alle 11:58
Mercoledì, 01/05/2013
va bene! Grazie.

PM Quote
Avatar
camaleonteplus (Normal User)
Pro


Messaggi: 95
Iscritto: 05/03/2009

Segnala al moderatore
Postato alle 17:17
Giovedì, 09/05/2013
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.

PM Quote