AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Änderung einer Deklarartion integer <-> double möglich?
Thema durchsuchen
Ansicht
Themen-Optionen

Änderung einer Deklarartion integer <-> double möglich?

Ein Thema von BAMatze · begonnen am 15. Jun 2009 · letzter Beitrag vom 15. Jun 2009
 
BAMatze

Registriert seit: 18. Aug 2008
Ort: Berlin
759 Beiträge
 
Turbo Delphi für Win32
 
#14

Re: Änderung einer Deklarartion integer <-> double mög

  Alt 15. Jun 2009, 14:44
Also habe das jetzt erstmal wie folgt gelöst:

Delphi-Quellcode:
type TZahltyp = (ZtGanzzahl, ZtposGanzzahl, ZtGleitkommazahl, ZtposGleitkommazahl);

Type TLabZahlEdit = Class(TWinControl)
  private
    ...
    FvValue: Variant;
    ...
    procedure SetValue(vWert: Variant);
    function GetValue: Variant;
  protected
    ...
  published
    ...
    property Value: Variant read GetValue write SetValue;
  public
    ...
end;

procedure TLabZahlEdit.SetValue(vWert: Variant);
var sTemp: string;
    dTemp: double;
    iTemp: integer;
begin
  // es muss bei der Konvertierung darauf geachtet werden, dass ein int auch in
  // ein double umgewandelt werden kann und somit muss anhand des eingestellten
  // Zahlentyps die richtige Konvertierung durchgeführt werden.
  sTemp := vartostr(vWert);
  if sTemp <> Null then
    begin
      case FEdEingabe.Zahlart of
        Ganzzahl: if trystrtoint(sTemp, iTemp) then
                             begin
                               FvValue := vWert;
                               SetText(sTemp);
                             end;
        posGanzzahl: if trystrtoint(sTemp, iTemp) then
                             begin
                               FvValue := vWert;
                               SetText(sTemp);
                             end;
        Gleitkommazahl: if trystrtofloat(sTemp, dTemp) then
                             begin
                               FvValue := vWert;
                               SetText(sTemp);
                             end;
        posGleitkommazahl: if trystrtofloat(sTemp, dTemp) then
                             begin
                               FvValue := vWert;
                               SetText(sTemp);
                             end;
      end;
    end;
end;

function TLabZahlEdit.GetValue: Variant;
var sTemp: string;
    iTemp: integer;
    dTemp: double;
begin
  sTemp := vartostr(FvValue);
  case FEdEingabe.Zahlart of
    Ganzzahl: if trystrtoint(sTemp, iTemp) then result := strtoint(sTemp);
    posGanzzahl: if trystrtoint(sTemp, iTemp) then result := strtoint(sTemp);
    Gleitkommazahl: if trystrtofloat(sTemp, dTemp) then result := strtofloat(sTemp);
    posGleitkommazahl: if trystrtofloat(sTemp, dTemp) then FvValue := strtofloat(sTemp);
  end;
end;
Könnt ihr euch ja vieleicht mal anschauen, ob ich da jetzt einen Denkfehler drin hab oder ob das ok ist. Danke euch auf jeden Fall für eure Anregungen.

MfG
BAMatze
2. Account Sero
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:32 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz