Visualizzazione dei risultati da 1 a 5 su 5

Discussione: dynamic dataset delphi

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    5

    dynamic dataset delphi

    Ciao,
    è possibile creare un dataset dinamico in delphi 7?
    Cioè creare i campi e valorizzarli da codice?

    Grazie


  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,301
    Cosa intendi per "valorizzare?

    Intendi "creare dinamicamente una tabella tramite codice a runtime definendone il nome e i campi, nonchè riempirli con i dati"?

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    5
    esattamente!!!

  4. #4
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,301

    Esempio...

    Questo è un esempio di codice tratto dalla Guida in linea di Delphi:

    codice:
    with Table1 do begin
      Active := False;  
      DatabaseName := 'DBDEMOS';
      TableType := ttParadox;
      TableName := 'CustInfo';
    
      { Don't overwrite an existing table }
    
      if not Table1.Exists then begin
        { The Table component must not be active }
        { First, describe the type of table and give }
        { it a name }
        { Next, describe the fields in the table }
        with FieldDefs do begin
          Clear;
          with AddFieldDef do begin
            Name := 'Field1';
            DataType := ftInteger;
            Required := True;
          end;
          with AddFieldDef do begin
            Name := 'Field2';
            DataType := ftString;
            Size := 30;
          end;
        end;
        { Next, describe any indexes }
        with IndexDefs do begin
          Clear;
          { The 1st index has no name because it is
          { a Paradox primary key }
          with AddIndexDef do begin
            Name := '';
            Fields := 'Field1';
            Options := [ixPrimary];
          end;
          with AddIndexDef do begin
            Name := 'Fld2Indx';
            Fields := 'Field2';
            Options := [ixCaseInsensitive];
          end;
        end;
        { Call the CreateTable method to create the table }
        CreateTable;
      end;
    end;
    Si tratta di definire il database di lavoro, il nome della tabella, aggiungere la struttura dei campi e le relative caratteristiche.

    L'esempio riportato sopra è relativo al BDE, così come quello riportato qui sotto, sempre preso dalla Guida in linea, il quale mostra come accodare un record alla tabella, compilare i campi con un valore e salvare le modifiche.

    codice:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      SampleTable.Append;
      SampleTable.FieldValues['ALPHANUMERIC'] := Edit1.text;
      SampleTable.FieldValues['INTEGER'] := StrToInt(Edit2.text);
      SampleTable.Post;
    end;
    Purtroppo non ho il tempo materiale di elaborare esempi più estesi.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    5
    Grazie!!!


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.