AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Edit.Text ohne DB oder INI Speichern

Ein Thema von Amenovis · begonnen am 30. Nov 2018 · letzter Beitrag vom 15. Dez 2018
Antwort Antwort
Seite 1 von 6  1 23     Letzte »    
Amenovis

Registriert seit: 16. Nov 2011
52 Beiträge
 
#1

Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 14:55
Ein Editfeld behält den Wert der vor der Compilierung angegeben wurde. Wenn ich nun den Text ändere und das Programm neustarte übernimmt das Editfeld ja wieder den Wert zur Zeit der Compilierung..

Natürlich könnte ich den Wert in eine DB schreiben oder in eine INI und bei neustart beides auslesen und den Wert dann dem Editfeld wieder zu weisen... bei Änderung wird dann der neue Wert in die DB oder INI übernommen....USW.

Wie das geht weis ich die Frage ist ob es nicht eine einfachere Möglichkeit gibt, den text im editfeld vor beenden des Programms zu speichern und bei neustart wieder im besagten editfeld erscheinen zu lassen ?

LG

Timo
  Mit Zitat antworten Zitat
DieDolly

Registriert seit: 22. Jun 2018
2.175 Beiträge
 
#2

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 14:59
Einfacher als in eine Ini-Datei geht wohl nicht.

Vielleicht ist es aber einfacher die hier zu verwenden
Delphi-Quellcode:
Edit1.Text := TFile.ReadAllText(Datei);

TFile.WriteAllText(Datei, Edit1.Text);
  Mit Zitat antworten Zitat
Amenovis

Registriert seit: 16. Nov 2011
52 Beiträge
 
#3

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 15:05
Ok dank dir

Es geht dabei nicht um schwer auch wenn ich einfacher geschrieben habe Es geht dabei um eine Extra Datei für einen blöden Wert oder eine Extra Spalte in einer Tabelle bzw eine Tabelle für einen sich ändernden Wert

Aber ok dann mach ich mir eine extra Tabelle... Die DB ist ehh vorhanden und ich hab keine Extra Datei..

gruß
Timo
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 15:08
Eine Alternative könntre auch eine Speicherung in der Registry sein.
Markus Kinzler
  Mit Zitat antworten Zitat
Amenovis

Registriert seit: 16. Nov 2011
52 Beiträge
 
#5

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 15:17
Oha ok auf die Idee wäre ich jetzt nicht gekommen obwohl ich weiss das es möglich ist...Aber davon hab ich 0 Ahnung und vor Registry hab ich auch echt Respekt was kaput zu machen. Da lass ich lieber die Finger von

Aber trotzdem Danke

LG

Timo
  Mit Zitat antworten Zitat
Benutzerbild von dummzeuch
dummzeuch

Registriert seit: 11. Aug 2012
Ort: Essen
1.468 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#6

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 16:09
Irgendwo muss der Wert ja gespeichert werden. Früher, unter DOS konnte man noch das Executable patchen, aber unter Windows geht das nicht mehr, weil ein Schreibzugriff auf die Datei nicht möglich ist, wenn das Programm läuft. Virenscanner reagieren auf sowas aber auch allergisch.

Also bleibt nur:
* Eine zusätzliche Datei
* Ein Dienst, der die Daten für Dich speichert (Datenbank, "Cloud"-Server)
* Die Registry (die im Grunde auch nur eine zusätzliche Datei ist)

Oder halt der User, der sich die Wert merkt und immer wieder eintippt.
Thomas Mueller
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 16:17
Wenns nur flüchtige Werte sein brauchen, eventuell über ClipBoard was zaubern?
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#8

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 17:55
Wenns nur flüchtige Werte sein brauchen, eventuell über ClipBoard was zaubern?
Und damit den Inhalt des Benutzers unerwartet zerschießen?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 18:03
Wenns nur flüchtige Werte sein brauchen, eventuell über ClipBoard was zaubern?
Und damit den Inhalt des Benutzers unerwartet zerschießen?
Ich hatte da eher sowas im Sinne.

Hier copy/paste von da falls der Link tot geht.
Delphi-Quellcode:
// The TClipboard provides easy clipboard access. But what if you
// want to add (several) custom defined items to the clipboard?

// For all actions is the unit Clipboard required.
uses Clipboard;

// First you have to register your own ClipBoard format
// Zuerst registrieren wir unser eigenes ClipBoard Format
const
  MyClipboardFormatStr = 'MyData';

var
  MyClpFormat: integer;

  MyClpFormat := RegisterClipboardFormat(MyClipboardFormatStr);

{ The variable SLMClpFormat will contain a unique format handle for
  your own clipboard format.

  Die Variable SLMClpFormat enthält ein einzigartiges Format Handle
  für unser ClipBoard Format.
}


procedure IncPointer(var p: Pointer; increment: Integer);
begin
  p := PChar(p) + Increment;
end;

// Say you have a data record defined as:
// Definiere zuerst etwa einen solchen Daten Record:
type
  PMyDataRec = ^TMyDataRec;
  TMyDataRec = record
    Name: string[50];
    Value: Integer;
  end;

{ Furthermore let's say the data records are stored in a Listbox
  and shall be copied to a list box.

  Angenommen, die Daten Records sind in einer ListBox gespeichert und
  sollen in eine ListBox kopiert werden.
}


  // Copy like this:
procedure TForm1.CopyItems;
var
  i: integer;
  dh: THandle;
  ic: integer;
  p: Pointer;
  pi: pInteger;
begin
  // get number of items to be copied
  // Die Anzahl zu kopierenden Items
  ic := List1.SelCount;
  dh := GlobalAlloc(GMEM_FIXED or GMEM_ZEROINIT,
    (SizeOf(TMyDataRec) * ic) + SizeOf(Integer));
  { allocate memory for all items plus for a integer variable giving you the number of
    copied items }

  p := GlobalLock(dh); { Lock the allocated memory }
  pi := pInteger(p);
  pi^ := ic; { write number of items to allocated memory }
  IncPointer(p, SizeOf(Integer)); { increment the pointer behind the written data }
  // You don't have to create an instance of clipboard, this is done automatically

  for i := 1 to List1.Items.Count do { check all items if they are selected }
  begin
    if List1.Items[i - 1].Selected then
    begin
      { This one is selected -> copy it o the clipboard }
      PMyDataRec(p)^ := PMyDataRec(List1.Items[i - 1].Data)^;
      { of course data must point to a TMyDataRec }
      IncPointer(p, SizeOf(TMyDataRec));
      { increment the pointer behind the written data }
    end;
  end;

  // You have now filled the allocated memory with all items that shall be copied.
  // Now you can put them to the clipboard
  Clipboard.Open; { Open the clipboard will prevent overwriting of so far copied items }
  Clipboard.Clear; { Clear the clipboard first }
  Clipboard.SetAsHandle(MyClpFormat, Dh); { Copy to clipboard }
  Clipboard.Close; { finally close the clipboard }
  GlobalUnlock(dh);
  { and unlock the allocate memory. But don't free it, it will be used by the clipboard }

  if ic = 0 then
    GlobalFree(dh); { You can free it if you haven't copied anything }
end;

// Check first if your items are still available before pasting them from the clipbard

if Clipboard.HasFormat(MyClpFormat) then
begin
  Form1.Paste1.Enabled := True; { Yes, they are still available }
end;

// And this is, how you paste them after Paste1 is clicked
procedure TMDIForm.Paste1Click(Sender: TObject);
var
  dh: THandle;
  pdr: PSLMDataRec;
  i, ic: integer;
  p: Pointer;
  pi: pInteger;
  li: TListItem;
begin
  if Clipboard.HasFormat(MyClpFormat) then
  // We have already checked, but maybe another application has overwritten the
  // clipboard in between....
  begin
    ClipBoard.Open; { First open the clipboard again }
    dh := Clipboard.GetAsHandle(MyClpFormat); { Catch the handle to the stored items }
    p := GlobalLock(dh); { and lock it }
    pi := pInteger(p); { The first item is an integer giving the number of items }
    ic := pi^; { so get the number of items }
    IncPointer(p, SizeOf(Integer)); { increment the pointer behind the read data }
    for i := 1 to ic do { get all copied items one after another }
    begin
      li := List1.Items.Add; { first create a new listbox item }
      pdr := New(PMyDataRec); { Then create a new pointer to a TMyDataRec }
      pdr^ := PMyDataRec(p)^; { and fill it with data from the clipboard }
      IncPointer(p, SizeOf(TSLMDataRec));
      { increment the pointer behind the written data }

      li.Data := pdr; { Set the data pointer of the list item to the new record }
      LI.Caption := pdr^.Name; { Let the item display the record field "Name" }

      // You can of course add more record fields if the item has subitems:
      LI.SubItems.Add(IntToStr(Value));
    end; { All data retrieved from clipboard }
    Clipboard.Close; { Close it }
    GlobalUnlock(dh);
   { and unlock the pointer, but don't free it. This will be done by the clipboard itself,
     if necessary }

  end;
end;
Gruß vom KodeZwerg

Geändert von KodeZwerg (30. Nov 2018 um 18:07 Uhr)
  Mit Zitat antworten Zitat
DieDolly

Registriert seit: 22. Jun 2018
2.175 Beiträge
 
#10

AW: Edit.Text ohne DB oder INI Speichern

  Alt 30. Nov 2018, 18:35
So ein Aufwand, obwohl es auch 2 Zeilen absolut tun?
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 6  1 23     Letzte »    


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 07:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz