Recent

Author Topic: how to load or add more than one URL path in a listbox..  (Read 5631 times)

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
Re: how to load or add more than one URL path in a listbox..
« Reply #15 on: January 18, 2019, 12:52:14 am »
good day,
         thank you very much sir for giving time in helping me with my project, here are the codes that im using, sorry if i can't send a compressed file of my project..there's a problem in my connection..thank you again in advance.... O:-) O:-) O:-) O:-) :D :D :D


Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, sqldb, db, sqlite3conn, FileUtil, RTTICtrls, Forms,
  9.   Controls, Graphics, Dialogs, StdCtrls, ComCtrls, lclintf, ExtCtrls, DbCtrls,
  10.   DBGrids, FileCtrl, Types;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     Button2: TButton;
  18.     Image1: TImage;
  19.     Label1: TLabel;
  20.     Label2: TLabel;
  21.     Edit1: TEdit;
  22.     Edit2: TEdit;
  23.     Button1: TButton;
  24.     Label3: TLabel;
  25.     Label4: TLabel;
  26.     ListBox1: TListBox;
  27.     SQLite3Connection1: TSQLite3Connection;
  28.     SQLQuery1: TSQLQuery;
  29.     SQLTransaction1: TSQLTransaction;
  30.     StatusBar1: TStatusBar;
  31.     procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
  32.     procedure FormCreate(Sender: TObject);
  33.     procedure FormDestroy(Sender: TObject);
  34.     procedure Button1Click(Sender: TObject);
  35.     procedure ListBox1Click(Sender: TObject);
  36.     procedure ListBox1SelectionChange(Sender: TObject; User: boolean);
  37.     procedure StatusBar1DblClick(Sender: TObject);
  38.   private
  39.     FUrlList: TStringList;
  40.     function ValidFields: Boolean;
  41.   public
  42.  
  43.   end;
  44.  
  45. var
  46.   Form1: TForm1;
  47.   var uname:string;
  48.   procedure GetData;
  49.  
  50. implementation
  51.  
  52. uses LCLType;
  53.  
  54. {$R *.lfm}
  55.  
  56. resourcestring
  57.   sInvalidFields = 'You must fill *both* fields!';
  58.  
  59. { TForm1 }
  60.  
  61. function TForm1.ValidFields: Boolean;
  62. { TODO : A good and nice validation! }
  63. begin
  64.   Result := (Edit1.Text <> '') and (Edit2.Text <> '');
  65. end;
  66.  
  67. procedure TForm1.FormCreate(Sender: TObject);
  68. var
  69. i : string;
  70. begin
  71.   FUrlList := TStringList.Create;
  72.   { Cleanup design-time artifacts }
  73.   Edit1.Text := EmptyStr;
  74.   Edit2.Text := EmptyStr;
  75.   //LISTBOX1.ITEMS.LoadFromFile('WI_NAME');
  76.  
  77. begin
  78.  
  79.   i :='Select WI_NAME, WI_URL from ICP_DOCUS';
  80.  
  81.   SQLQuery1.Close;
  82.   SQLQuery1.SQL.Text := i;
  83.   SQLite3Connection1.Connected:=True;
  84.   SQLTransaction1.Active:=True;
  85.   SQLQuery1.Open;
  86.  
  87.   While Not SQLQuery1.EOF do begin
  88.    ListBox1.Items.Add(SQLQuery1.FieldByName('WI_NAME').AsString);
  89.   //ListBox1.Items.Add(SQLQuery1.FieldByName('WI_URL').AsString);
  90.   SQLQuery1.Next;
  91.   END;
  92.  
  93.  
  94.   GetData;
  95. end;
  96.  
  97. end;
  98.  
  99.  
  100.  
  101. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  102. begin
  103.     SQLQuery1.Close;
  104.   SQLite3Connection1.Connected := False;
  105.   SQLTransaction1.Active       := False;
  106. end;
  107.  
  108. procedure TForm1.FormDestroy(Sender: TObject);
  109. begin
  110.   FUrlList.Free;
  111. end;
  112.  
  113. procedure TForm1.Button1Click(Sender: TObject);
  114. var
  115.   Index: Integer;
  116.   sqlText: string;
  117. begin
  118.   if ValidFields then begin
  119.     Index := FUrlList.IndexOf(Edit1.Text);
  120.     if Index >= 0 then
  121.       { URL is already stored, so update Listbox }
  122.       ListBox1.Items[Index] := Edit2.Text
  123.     else begin
  124.       { New URL: Store it and update ListBox }
  125.       FUrlList.Add(Edit1.Text);
  126.       ListBox1.Items.Add(Edit2.Text);
  127.     end;
  128.   end else
  129.     ShowMessage(sInvalidFields);
  130.  
  131.   begin
  132.     sqlText := 'INSERT INTO ICP_DOCUS(WI_NAME, WI_URL) ' +
  133.              'VALUES(:WI_NAME, :WI_URL)';
  134.   SQLQuery1.Close;
  135.   SQLQuery1.SQL.Text := sqlText;
  136.   SQLQuery1.Params.ParamByName('WI_URL').AsString  := Trim(Edit1.Text);
  137.   SQLQuery1.Params.ParamByName('WI_NAME').AsString := Trim(Edit2.Text);
  138.   SQLQuery1.ExecSQL;
  139.   SQLTransaction1.Commit;
  140.  
  141.   ShowMessage('Saved!');
  142.  
  143.   Edit1.clear;
  144.   Edit2.Clear;
  145.  
  146.  
  147.   GetData;
  148.  
  149.   end;
  150.  
  151.  
  152.  
  153. {$ifdef debug -- let's make a little check}
  154.   Assert(FUrlList.Count = ListBox1.Items.Count,
  155.          Format('Wrong items count: FUrlist %d vs. ListBox %d',
  156.                 [FUrlList.Count, ListBox1.Items.Count);
  157. {$endif}
  158. //LISTBOX1.ITEMS.SAVETOFILE('TRY.TXT');
  159. end;
  160.  
  161. procedure TForm1.ListBox1Click(Sender: TObject);
  162. begin
  163.   statusbar1.simpletext:=listbox1.items[listbox1.itemindex]
  164. end;
  165.  
  166. procedure TForm1.ListBox1SelectionChange(Sender: TObject; User: boolean);
  167. var
  168.   sqlText: string;
  169. begin
  170.  
  171.   sqlText := 'SELECT WI_URL FROM ICP_DOCUS';
  172.  
  173.  
  174.   Form1.SQLQuery1.Close;
  175.   Form1.SQLQuery1.SQL.Text := sqlText;
  176.   Form1.SQLite3Connection1.Connected := True;
  177.   Form1.SQLTransaction1.Active       := True;
  178.   Form1.SQLQuery1.Open;
  179.  
  180.  
  181. end;
  182.  
  183. procedure TForm1.StatusBar1DblClick(Sender: TObject);
  184. var
  185. i : string;
  186. begin
  187.   i :='Select WI_URL from ICP_DOCUS';
  188.  
  189.   SQLQuery1.Close;
  190.   SQLQuery1.SQL.Text := i;
  191.   SQLite3Connection1.Connected:=True;
  192.   SQLTransaction1.Active:=True;
  193.   SQLQuery1.Open;
  194.  
  195.   OpenURL(Statusbar1.simpleText);
  196. end;
  197.  
  198. procedure GetData;
  199. var
  200.   sqlText: string;
  201. begin
  202.  
  203.   sqlText := 'SELECT WI_NAME FROM ICP_DOCUS';
  204.  
  205.   Form1.SQLQuery1.Close;
  206.   Form1.SQLQuery1.SQL.Text := sqlText;
  207.   Form1.SQLite3Connection1.Connected := True;
  208.   Form1.SQLTransaction1.Active       := True;
  209.   Form1.SQLQuery1.Open;
  210.  
  211. end;
  212.  
  213. //procedure GetData2;
  214. //var
  215. //  sqlText: string;
  216. //begin
  217. //
  218. //  sqlText := 'SELECT WI_URL FROM ICP_DOCUS';
  219. //
  220. //  Form1.SQLQuery1.Close;
  221. //  Form1.SQLQuery1.SQL.Text := sqlText;
  222. //  Form1.SQLite3Connection1.Connected := True;
  223. //  Form1.SQLTransaction1.Active       := True;
  224. //  Form1.SQLQuery1.Open;
  225. //
  226. //  Statusbar1.simpletext:=sqltext;
  227. //end;
  228. //
  229. end.
  230.  
« Last Edit: January 18, 2019, 12:55:40 am by iamtheatorres2408 »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: how to load or add more than one URL path in a listbox..
« Reply #16 on: January 18, 2019, 04:03:34 am »
The ICP_DOCS.rar you provided only contains the db file, you should also provide the source code files. Showing the source without provide the downloadable files isn't helpful. Because without the *.lfm file, it is hard to rebuild the compilable project.

If you want to attach the source code, here is how to do it:
Create a new folder, copy and paste all the necessary files except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here.

Today I'm nice. I have rebuilt it for you.
Anyone interested, you can download the test.zip below.
But what is the question, iamtheatorres2408?

 

TinyPortal © 2005-2018