Sayfayı Yazdır | Pencereyi Kapat

base64 formantından veri çekmek

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Genel İşlemler
Forum Tanımlaması: TRObject dili ile programlama yaparken karşılaşılan genel işlemler
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=692
Tarih: 06 Ocak 2025 Saat 13:26
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: base64 formantından veri çekmek
Mesajı Yazan: ahmet
Konu: base64 formantından veri çekmek
Mesaj Tarihi: 17 Temmuz 2024 Saat 17:22
veritabanında base64 formatında tuttuğum veriyi tekrar kullanmak istiyorum nasıl kullanabilirim 



Cevaplar:
Mesajı Yazan: Developer
Mesaj Tarihi: 17 Temmuz 2024 Saat 17:46
Merhaba Ahmet,
Aşağıdaki kodu inceler misin?
var
   Port: Integer;
   Form1:TCLForm;
   qry : TClSQLiteQuery;
   MemStream: TclMemoryStream;
   BlobField: TBlobField;
   Img1 : TclImage;
   Base64String: string;
   BinaryData: TBytes;


 void OnGuideQryClick; 
 {
     try 
       Qry = Clomosy.DBSQLiteQueryWith('SELECT imgUrl FROM TBLDocs WHERE id = 23');
       qry.OpenOrExecute;
       if (qry.Found)
       {
       ShowMessage(qry.FieldByName('imgUrl').AsString);
         BlobField = qry.FieldByName('imgUrl') as TBlobField;
         //MemStream = TclMemoryStream.Create;
         BlobField.SaveToStream(MemStream); // Load BLOB data into the stream
         MemStream.Position = 0;
         //Base64String = Clomosy.StreamToBase64(MemStream);
         //Clomosy.setClipBoard(Base64String);//FOR TEST PURPOSE COPIES BASE6
         //Img1.Bitmap.LoadFromStream(MemStream); // Load the image from the stream
         Img1.Bitmap.LoadFromStream(MemStream);
         MemStream.Free;
         
       }
     except
       ShowMessage('[019] Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
     }
}

   void SqLiteInsertData;
  {
    try

      Base64String = Clomosy.FileToBase64(clPathCombine('1Top.png',Clomosy.AppFilesPath));
      MemStream = TclMemoryStream.Create();
      MemStream = Clomosy.Base64ToStream(Base64String);
      
      //BinaryData := TNetEncoding.Base64.DecodeStringToBytes(Base64String);
    //  Clomosy.DBSQLiteQuery.Sql.Text = '
    //INSERT INTO TBLDocs (id, imgName,imgUrl) VALUES (1,''Image 1'','''+Clomosy.FileToBase64(clPathCombine('1Top.png',Clomosy.AppFilesPath))+''');'; //addassetfromurl ile dosyaları indir
      //Clomosy.DBSQLiteQuery.
        ShowMessage(Clomosy.AppFilesPath);
        base64String = Clomosy.FileToBase64(clPathCombine('1Top.png',Clomosy.AppFilesPath));
        Clomosy.DBSQLiteQuery.SQL.Text = 'INSERT INTO TBLDocs (id, imgName, imgUrl) VALUES (23, ''test'', :imgUrl)';
        //Clomosy.DBSQLiteQuery.ParamByName('imgName').AsString = 'Image from Base64';
        Clomosy.DBSQLiteQuery.ParamByName('imgUrl').value = MemStream;
      
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      // https://clomosy.com/learn/1Top.png" rel="nofollow - https://clomosy.com/learn/1Top.png
      ShowMessage('Adding data to the table was successful!');
    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
  
  void SqLiteConnectionCreateTable;
  var
    TableExists: Boolean;
  {
    try
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBDocsFile.db3', '');
 
      // Check if the table exists
      Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="TBLDocs";';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      
      // Check the results
      TableExists = not Clomosy.DBSQLiteQuery.Eof;
      
      // Create the table if it does not exist
      if not (TableExists)
      {
        Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE TBLDocs (
                                          id INTEGER PRIMARY KEY,
                                          imgName TEXT NOT NULL,
                                          imgUrl BLOB NOT NULL
                                          );';
        Clomosy.DBSQLiteQuery.OpenOrExecute;
        
        ShowMessage('Table successfully added to the database!');
        
      } else
      {
        ShowMessage('The Products table already exists.');
      }

    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }

  {
    Form1 = TclForm.Create(Self);
        ShowMessage(Clomosy.AppFilesPath);
    Img1 = Form1.AddNewImage(Form1,'Img1');
    Img1.Align = alClient;
    SqLiteConnectionCreateTable;
    SqLiteInsertData;
    OnGuideQryClick;
    Form1.Run;
  }



Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net