Programlama yapalım ve Öğrenelim. - Delphi Eğitim222
  Ana Sayfa
  .NET Eğitim Notları
  Visual C# .NET Örnek Kodları
  VisualBasic.NET Örnek Kodları
  J# Örnekleri
  ASP.NET Örnek Kodları
  Delphi Eğitim
  => Delphi Eğitim1
  => Delphi Eğitim2
  => Delphi Eğitim3
  => Delphi Eğitim4
  => Delphi Eğitim5
  => Delphi Eğitim6
  => Delphi Eğitim7
  => Delphi Eğitim8
  => Delphi Eğitim9
  => Delphi Eğitim10
  => Delphi Eğitim11
  => Delphi Eğitim13
  => Delphi Eğitim14
  => Delphi Eğitim15
  => Delphi Eğitim16
  => Delphi Eğitim17
  => Delphi Eğitim18
  => Delphi Eğitim19
  => Delphi Eğitim20
  => Delphi Eğitim21
  => Delphi Eğitim22
  => Delphi Eğitim23
  => Delphi Eğitim24
  => Delphi Eğitim25
  => Delphi Eğitim26
  => Delphi Eğitim27
  => Delphi Eğitim28
  => Delphi Eğitim29
  => Delphi Eğitim30
  => Delphi Eğtim31
  => Delphi Eğitim32
  => Delphi Eğitim33
  => Delphi Eğitim34
  => Delphi Eğitim35
  => Delphi Eğitim36
  => Delphi Eğitim37
  => Delphi Eğitim38
  => Delphi Eğitim39
  => Delphi Eğitim40
  => Delphi Eğitim41
  => Delphi Eğitim42
  => Delphi Eğitim43
  => Delphi Eğitim44
  => Delphi Eğitim45
  => Delphi Eğitim46
  => Delphi Eğitim47
  => Delphi Eğitim48
  => Delphi Eğitim49
  => Delphi Eğitim50
  => Delphi Eğitim51
  => Delphi Eğitim52
  => Delphi Eğitim53
  => Delphi Eğitim54
  => Delphi Eğitim55
  => Delphi Eğitim56
  => Delphi Eğitim57
  => Delphi Eğitim58
  => Delphi Eğitim59
  => Delphi Eğitim60
  => Delphi Eğitim61
  => Delphi Eğitim62
  => Delphi Eğitim63
  => Delphi Eğitim64
  => Delphi Eğitim65
  => Delphi Eğitim66
  => Delphi Eğitim67
  => Delphi Eğitim68
  => Delphi Eğitim69
  => Delphi Eğitim70
  => Delphi Eğitim71
  => Delphi Eğitim72
  => Delphi Eğitim73
  => Delphi Eğitim74
  => Delphi Eğitim75
  => Delphi Eğitim76
  => Delphi Eğitim77
  => Delphi Eğitim78
  => Delphi Eğitim79
  => Delphi Eğitim80
  => Delphi Eğitim81
  => Delphi Eğitim82
  => Delphi Eğitim83
  => Delphi Eğitim84
  => Delphi Eğitim85
  => Delphi Eğitim86
  => Delphi Eğitim87
  => Delphi Eğitim88
  => Delphi Eğitim89
  => Delphi Eğitim90
  => Delphi Eğitim91
  => Delphi Eğitim92
  => Delphi Eğitim93
  => Delphi Eğitim94
  => Delphi Eğitim95
  => Delphi Eğitim96
  => Delphi Eğitim97
  => Delphi Eğitim98
  => Delphi Eğitim99
  => Delphi Eğitim100
  => Delphi Eğitim101
  => Delphi Eğitim102
  => Delphi Eğitim103
  => Delphi Eğitim104
  => Delphi Eğitim105
  => Delphi Eğitim106
  => Delphi Eğitim107
  => Delphi Eğitim108
  => Delphi Eğitim109
  => Delphi Eğitim110
  => Delphi Eğitim111
  => Delphi Eğitim112
  => Delphi Eğitim113
  => Delphi Eğitim114
  => Delphi Eğitim115
  => Delphi Eğitim116
  => Delphi Eğitim117
  => Delphi Eğitim118
  => Delphi Eğitim119
  => Delphi Eğitim120
  => Delphi Eğitim121
  => Delphi Eğitim122
  => Delphi Eğitim123
  => Delphi Eğitim124
  => Delphi Eğitim125
  => Delphi Eğitim126
  => Delphi Eğitim127
  => Delphi Eğitim128
  => Delphi Eğitim129
  => Delphi Eğitim130
  => Delphi Eğitim131
  => Delphi Eğitim132
  => Delphi Eğitim133
  => Delphi Eğitim134
  => Delphi Eğitim135
  => Delphi Eğitim136
  => Delphi Eğitim137
  => Delphi Eğitim138
  => Delphi Eğitim139
  => Delphi Eğitim140
  => Delphi Eğitim141
  => Delphi Eğitim142
  => Delphi Eğitim143
  => Delphi Eğitim144
  => Delphi Eğitim145
  => Delphi Eğitim146
  => Delphi eğitim147
  => Delphi Eğitim148
  => Delphi Eğitim149
  => Delphi Eğitim150
  => Delphi Eğitim151
  => Delphi Eğitim152
  => Delphi Eğitim153
  => Delphi Eğitim154
  => Delphi Eğitim155
  => Delphi Eğitim156
  => Delphi Eğitim157
  => Delphi Eğitim158
  => Delphi Eğitim159
  => Delphi Eğitim160
  => Delphi Eğitim161
  => Delphi Eğitim162
  => Delphi Eğitim164
  => Delphi Eğitim165
  => Delphi Eğitim166
  => Delphi Eğitim167
  => Delphi Eğitim168
  => Delphi Eğitim169
  => Delphi Eğitim170
  => Delphi Eğitim171
  => Delphi Eğitim172
  => Delphi Eğitim173
  => Delphi Eğitim174
  => Delphi Eğitim175
  => Delphi Eğitim176
  => Delphi Eğitim177
  => Delphi Eğitim178
  => Delphi Eğitim179
  => Delphi Eğitim180
  => Delphi Eğitim181
  => Delphi Eğitim182
  => Delphi Eğitim183
  => Delphi Eğitim184
  => Delphi Eğitim185
  => Delphi Eğitim186
  => Delphi Eğitim187
  => Delphi Eğitim188
  => Delphi Eğitim189
  => Delphi Eğitim190
  => Delphi Eğitim191
  => Delphi Eğitim192
  => Delphi Eğitim193
  => Delphi Eğitim194
  => Delphi Eğitim195
  => Delphi Eğitim196
  => Delphi Eğitim197
  => Delphi Eğitim198
  => Delphi Eğitim199
  => Delphi Eğitim200
  => Delphi Eğitim201
  => Delphi Eğitim202
  => Delphi Eğitim203
  => Delphi Eğitim204
  => Delphi Eğitim205
  => Delphi Eğitim206
  => Delphi Eğitim207
  => Delphi Eğitim208
  => Delphi Eğitim209
  => Delphi Eğitim210
  => Delphi Eğitim211
  => Delphi Eğitim212
  => Delphi Eğitim213
  => Delphi Eğitim214
  => Delphi Eğitim215
  => Delphi Eğitim216
  => Delphi Eğitim217
  => Delphi Eğitim218
  => Delphi Eğitim219
  => Delphi Eğitim220
  => Delphi Eğitim221
  => Delphi Eğitim222
  => Delphi Eğitim223
  => Delphi Eğitim224
  => Delphi Eğitim225
  => Delphi Eğitim226
  => Delphi Eğitim227
  => Delphi Eğitim228
  => Delphi Eğitim229
  => Delphi Eğitim230
  => Delphi Eğitim231
  => Delphi Eğitim232
  => Delphi Eğitim233
  => Delphi Eğitim234
  => Delphi Eğitim235
  => Delphi Eğitim236
  => Delphi Eğitim237
  => Delphi Eğitim238
  => Delphi Eğitim239
  => Delphi Eğitim240
  => Delphi Eğitim241
  => Delphi Eğitim242
  İletişim

 

YTL ve Ykr Çevrimi Dikkat

//------------MoRFiN------------

//----cw_morfin@msn.com---------

//----delphi_hacker@hotmail.com-

 

procedure TDMData.ALANGetText(Sender: TField; var Text: String;

  DisplayText: Boolean);

  var

    Deger: Variant;

    Birim: String;

begin

  DisplayText:= True;

  if (Sender.DataType in [ftFloat]) then

  begin

    Deger:= Sender.AsFloat;

    if (Deger < 1) then

    begin

      Birim:= 'YKr';

      Deger:= Deger*100;

    end

    else

      Birim:= 'YTL';

    Text:= FormatFloat('###,###.00 '+Birim, Deger);

    Exit;

  end else

  begin

    Text:= Sender.AsString;

  end;

 

  if Sender.AsString = '0' then

  begin

    Text:= '0 YTL';

  end;

 

 

 

MDI Form Çalıştırma 2

//------------MoRFiN------------

//----cw_morfin@msn.com---------

//----delphi_hacker@hotmail.com-

begin

  if Application.FindComponent('Form2') = Nil then

    Application.CreateForm(TForm2, Form2);

  Form2.Show;

end;

 

Delphi - .....................................

 

Birkere Acılsın MIDI

// Aslında bu başlıkta bir kod vardı ama ben çalıştıramayınca yenisini gönderdim

 

 

if TForm(Application.FindComponent('form_Name'))<>nil then

begin

  form_Name.Show;

  form_Name.WindowState:=wsMaximized;

  Exit;

end;

 form_Name:=Tform_Name.Create(Application);

 

Delphi - .....................................

 

Birkere Acılsın MIDI

// Aslında bu başlıkta bir kod vardı ama ben çalıştıramayınca yenisini gönderdim

 

 

if TForm(Application.FindComponent('form_Name'))<>nil then

begin

  form_Name.Show;

  form_Name.WindowState:=wsMaximized;

  Exit;

end;

 form_Name:=Tform_Name.Create(Application);

 

Delphi - .....................................

 

Çalışma Anında Create Edilmis Form Listesini Almak.

procedure TForm1.Button1Click(Sender: TObject);

var i: integer;

begin

 

for i := 0 to Application.ComponentCount -1 do

begin

 

if (Application.Components[i] is TForm) then

begin

 Memo1.Lines.Add( (Application.Components[i] as TForm).Name );

end;

 

end;

 

end;

 

Delphi - .....................................

 

Çalışma Anında Create Edilmis Form Listesini Almak.

procedure TForm1.Button1Click(Sender: TObject);

var i: integer;

begin

 

for i := 0 to Application.ComponentCount -1 do

begin

 

if (Application.Components[i] is TForm) then

begin

 Memo1.Lines.Add( (Application.Components[i] as TForm).Name );

end;

 

end;

 

end;

 

Delphi - .....................................

 

fazla satır yazmak yerine 4-5 satırla işi haledin çook hoş bişi yaa bu

Button1.Enabled := True ;

  Button2.Enabled := True ;

  Button3.Enabled := True ;

  Button4.Enabled := True ;

  Button5.Enabled := True ;

  Button6.Enabled := True ;

  Button7.Enabled := True ;

  Button8.Enabled := True ;

  Button9.Enabled := False ; //dikkat******

  Button10.Enabled := True ;

  Button11.Enabled := True ;

  Button12.Enabled := True ;

  Button13.Enabled := True ;

  Button14.Enabled := True ;

 

  // Bu kadar satır yazmak yerine

  // FindComponent komutunu kullanabiliriz...!!!

  // Kullanılış biçimi...................*******

  // Bulunduğu_Sınıf(FindComponent( Nesne_adi : String + index : integer ) ).Özellik := değeri ;

  //.....................................*******

 

  for i:=1 to 14 do

    if i = 9 then

      TButton(FindComponent('Button'+IntToStr (i))).Enabled := False ;

    else

      TButton(FindComponent('Button'+IntToStr (i))).Enabled := True ;

 

Delphi - .....................................

 

fazla satır yazmak yerine 4-5 satırla işi haledin çook hoş bişi yaa bu

Button1.Enabled := True ;

  Button2.Enabled := True ;

  Button3.Enabled := True ;

  Button4.Enabled := True ;

  Button5.Enabled := True ;

  Button6.Enabled := True ;

  Button7.Enabled := True ;

  Button8.Enabled := True ;

  Button9.Enabled := False ; //dikkat******

  Button10.Enabled := True ;

  Button11.Enabled := True ;

  Button12.Enabled := True ;

  Button13.Enabled := True ;

  Button14.Enabled := True ;

 

  // Bu kadar satır yazmak yerine

  // FindComponent komutunu kullanabiliriz...!!!

  // Kullanılış biçimi...................*******

  // Bulunduğu_Sınıf(FindComponent( Nesne_adi : String + index : integer ) ).Özellik := değeri ;

  //.....................................*******

 

  for i:=1 to 14 do

    if i = 9 then

      TButton(FindComponent('Button'+IntToStr (i))).Enabled := False ;

    else

      TButton(FindComponent('Button'+IntToStr (i))).Enabled := True ;

 

Delphi - .....................................

 

Delphide Query ile kod yazarken dikkat  daha sonra veri girerken hata olurrrrrrr.....

function tara(metin:string):string;

var

  i : integer;

begin

  result:='';

  for i :=1  to length(metin) do

  begin

    if metin[i] = '''' then             // metinin i. index numaralı harfi '' (tek tırnak anlamına geliyor) varsa

        Result := Result +''''''        // onu '''' (Çift tınak anlamına geliyor) yap.

    else                     // Aksi taktirde

        result:=result + metin[i];      // metnin i. indexli oylece al 

  end;

end;

 

 

 

Delphi'de SQL kayıt yaparken eklenecek kaydın içinde  ' (sadece tek tırnak) geciyorsa bu

programda hataya neden olacaktır.

Çünkü:

  Query1.SQL.Add('insert into sinavveritaban(soruno, sorudata ) Values (%d, ''%s'')');

 

  SQL :=Format(CStr_InsertTemplate,

  [

   Strtoint(edtSoruSirasi.Text),

   tara(mmSoru.Text)  

  ]);

 

  Query1.SQL.Text :=SQL;

  Query1.ExecSQL;

 

  //soruno    =  5

  //sorudata  =  İstanbul'un Fethi ?

 

 

Query komut satırında %s bulunan bolume deger verirken ' bulundugu için komut satırı şu hali alacaktır.

 

insert into sinavveritaban(soruno, sorudata ) Values (5, ''İstanbul'un Fethi ?'')

 

(un Fethi ?) kısmını tanımlayamaz. ve hataya neden olur......

 

Delphi - .....................................

 

Delphide Query ile kod yazarken dikkat  daha sonra veri girerken hata olurrrrrrr.....

function tara(metin:string):string;

var

  i : integer;

begin

  result:='';

  for i :=1  to length(metin) do

  begin

    if metin[i] = '''' then             // metinin i. index numaralı harfi '' (tek tırnak anlamına geliyor) varsa

        Result := Result +''''''        // onu '''' (Çift tınak anlamına geliyor) yap.

    else                     // Aksi taktirde

        result:=result + metin[i];      // metnin i. indexli oylece al 

  end;

end;

 

 

 

Delphi'de SQL kayıt yaparken eklenecek kaydın içinde  ' (sadece tek tırnak) geciyorsa bu

programda hataya neden olacaktır.

Çünkü:

  Query1.SQL.Add('insert into sinavveritaban(soruno, sorudata ) Values (%d, ''%s'')');

 

  SQL :=Format(CStr_InsertTemplate,

  [

   Strtoint(edtSoruSirasi.Text),

   tara(mmSoru.Text)  

  ]);

 

  Query1.SQL.Text :=SQL;

  Query1.ExecSQL;

 

  //soruno    =  5

  //sorudata  =  İstanbul'un Fethi ?

 

 

Query komut satırında %s bulunan bolume deger verirken ' bulundugu için komut satırı şu hali alacaktır.

 

insert into sinavveritaban(soruno, sorudata ) Values (5, ''İstanbul'un Fethi ?'')

 

(un Fethi ?) kısmını tanımlayamaz. ve hataya neden olur......

 

Delphi - .....................................

 

Html Veri Çekme

{

Article:

Simple HTML page scraping with Delphi

 

http://delphi.about.com/library/weekly/aa062502a.htm

 

This article will show you the techniques nedded to

download an HTML page from the Internet, do some page

scraping (regular expressions for pattern matching)

and finally present the information in more

*situation-friendly* manner.

 

Download the ZIPed version.

}

 

 

MainForm.DFM

 

Select Form1,

Select View As Text,

Paste the text into Editor,

Select View As Form.

 

 

 

object Form1: TForm1

  Left = 240

  Top = 166

  Width = 290

  Height = 245

  Caption = 'Form1'

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'MS Sans Serif'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object Button1: TButton

    Left = 8

    Top = 8

    Width = 75

    Height = 25

    Caption = 'Button1'

    TabOrder = 0

    OnClick = Button1Click

  end

  object ListView1: TListView

    Left = 0

    Top = 40

    Width = 282

    Height = 178

    Align = alBottom

    Anchors = [akLeft, akTop, akRight, akBottom]

    Columns = <

      item

        Caption = 'Title'

      end

      item

        Caption = 'URL'

      end

      item

        Caption = 'Description'

      end

      item

        Caption = 'When/Where'

      end>

    TabOrder = 1

    ViewStyle = vsReport

  end

end

 

UNIT1.PAS

 

unit Unit1;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ComCtrls, StdCtrls, extactns;

 

type

  TForm1 = class(TForm)

    Button1: TButton;

    ListView1: TListView;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

 

 

function Download_HTM(const sURL, sLocalFileName:string): boolean;

begin

  Result:=True;

  with TDownLoadURL.Create(nil) do

  try

    URL:=sURL;

    Filename:=sLocalFileName;

    try

      ExecuteTarget(nil);

    except

      Result:=False

    end;

  finally

    Free;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

const

  ADPNEWHOTURL = 'http://delphi.about.com/cs/newandhot/index.htm';

  TmpFileName='c:temp_adp.newandhot';

var

  rawHTM, buffer, DataBuf, ItemBuf : string;

  sTitle, sLink, sDesc, SWhenWhere : string;

  NewAndHotHTMFile : TextFile;

  iStart, iStop : integer;

  stop: boolean;

begin

  if NOT Download_HTM(ADPNEWHOTURL,TmpFileName) then

  begin

    ShowMessage('Error in HTML file download');

    Exit;

  end;

 

    //read the HTML file

    AssignFile(NewAndHotHTMFile, TmpFileName);

    try

      Reset(NewAndHotHTMFile);

      while not EOF(NewAndHotHTMFile) do begin

        ReadLn(NewAndHotHTMFile, buffer);

        rawHTM := Concat(rawHTM, buffer);

      end;

 

      //START find the new and hot data on the page located between  <!--DCnt--> and </!--DCnt-->

      iStart := Pos('<!--DCnt-->',rawHTM) + Length('<!--DCnt-->');

      iStop := Pos('<!--/DCnt-->',rawHTM);

      DataBuf := Copy(rawHTM, iStart, iStop-iStart);

      if DataBuf='' then

      begin

        with ListView1.Items.Add do

        begin

          Caption:= 'Format error';

          SubItems.Add(ADPNEWHOTURL);

          SubItems.Add('The HTML file with the news is not formated properly!');

          SubItems.Add('in ' + TmpFileName);

        end;

        Exit;

      end;

      //STOP find the new and hot data on the page located between  <!--DCnt--> and </!--DCnt-->

 

      //start remove any script inside the htm page

      stop:=False;

      repeat

        iStart := Pos('<script>',DataBuf) ;

        if iStart <> 0 then

        begin

          iStop := Pos('</script>', DataBuf) + Length('</script>');

          DataBuf := Copy(DataBuf, 0, iStart - 1) + Copy(DataBuf, iStop, MaxInt);

        end

        else

          stop:=True;

      until stop;

      //stop remove any script inside the htm page

 

      ListView1.Clear;

 

      //start grab one item at a time (example):

      (*

      <p>

      <a href="/library/bluc/ucvcl.htm"><b>FREE CODE VCL: stMasterComboBox</b></a><br>

      <i>06/10 in <a href="/library/bluc/ucvcl.htm">FREE VCL</a>.</i> stMasterComboBox is a combo box component that helps you to create master-detail forms supplying navigation with a combo box.

      </p>

      *)

      stop:=False;

      repeat

        iStart := Pos('<p>',DataBuf) + Length('<p>') ;

        if (iStart <> 0) AND (DataBuf <> '') then

        begin

          //find one item

          iStop := Pos('</p>', DataBuf);

          ItemBuf := Copy(DataBuf, iStart, iStop - iStart);

 

          //remove that one

          Delete(DataBuf, 1, -1 + iStop + Length('</p>'));

 

          //find the link

          iStart:=Pos('<a href="',ItemBuf) + Length('<a href="');

          iStop:=Pos('">',ItemBuf);

          sLink:= 'http://delphi.about.com' +  Copy(ItemBuf, iStart, iStop-iStart);

 

          //find the title

          iStart:=Pos('<b>',ItemBuf) + Length('<b>');

          iStop:=Pos('</b>',ItemBuf);

          sTitle:= Copy(ItemBuf, iStart, iStop-iStart);

 

          //date and location (When/Where)

          iStart:=Pos('<i>',ItemBuf) + Length('<i>');

          iStop:=Pos('</i>',ItemBuf);

          SWhenWhere := Copy(ItemBuf, iStart, iStop-iStart);

          iStart:=Pos('<a href="',SWhenWhere);

          iStop:=Pos('">',SWhenWhere);

          Delete(SWhenWhere, iStart, iStop - iStart + Length('">'));

          SWhenWhere := StringReplace(SWhenWhere,'</a>','',[]);

 

          //find the description

          sDesc:=Copy(ItemBuf,Pos('</i>',ItemBuf) + Length('</i>'),MaxInt);

 

          //add to list view

          with ListView1.Items.Add do

          begin

            Caption:= sTitle;

            SubItems.Add(sLink);

            SubItems.Add(sDesc);

            SubItems.Add(sWhenWhere);

          end;

        end

        else

          stop:=True;

      until stop;

    //Stop grab one item at a time:

    finally

      CloseFile(NewAndHotHTMFile);

    end;

 

    //delete the temp file

    try

      DeleteFile(TmpFileName)

    except

    end;

 

end;

 

end.

 

Project1.PAS

 

program Project1;

 

uses

  Forms,

  Unit1 in 'Unit1.pas' {Form1};

 

{$R *.res}

 

begin

  Application.Initialize;

  Application.CreateForm(TForm1, Form1);

  Application.Run;

end.

 

 

{

********************************************

Zarko Gajic

About.com Guide to Delphi Programming

http://delphi.about.com

email: delphi.guide@about.com

free newsletter: http://delphi.about.com/library/blnewsletter.htm

forum: http://forums.about.com/ab-delphi/start/

********************************************

}

 

Delphi - .....................................

 

Html Veri Çekme

{

Article:

Simple HTML page scraping with Delphi

 

http://delphi.about.com/library/weekly/aa062502a.htm

 

This article will show you the techniques nedded to

download an HTML page from the Internet, do some page

scraping (regular expressions for pattern matching)

and finally present the information in more

*situation-friendly* manner.

 

Download the ZIPed version.

}

 

 

MainForm.DFM

 

Select Form1,

Select View As Text,

Paste the text into Editor,

Select View As Form.

 

 

 

object Form1: TForm1

  Left = 240

  Top = 166

  Width = 290

  Height = 245

  Caption = 'Form1'

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'MS Sans Serif'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object Button1: TButton

    Left = 8

    Top = 8

    Width = 75

    Height = 25

    Caption = 'Button1'

    TabOrder = 0

    OnClick = Button1Click

  end

  object ListView1: TListView

    Left = 0

    Top = 40

    Width = 282

    Height = 178

    Align = alBottom

    Anchors = [akLeft, akTop, akRight, akBottom]

    Columns = <

      item

        Caption = 'Title'

      end

      item

        Caption = 'URL'

      end

      item

        Caption = 'Description'

      end

      item

        Caption = 'When/Where'

      end>

    TabOrder = 1

    ViewStyle = vsReport

  end

end

 

UNIT1.PAS

 

unit Unit1;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ComCtrls, StdCtrls, extactns;

 

type

  TForm1 = class(TForm)

    Button1: TButton;

    ListView1: TListView;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

 

 

function Download_HTM(const sURL, sLocalFileName:string): boolean;

begin

  Result:=True;

  with TDownLoadURL.Create(nil) do

  try

    URL:=sURL;

    Filename:=sLocalFileName;

    try

      ExecuteTarget(nil);

    except

      Result:=False

    end;

  finally

    Free;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

const

  ADPNEWHOTURL = 'http://delphi.about.com/cs/newandhot/index.htm';

  TmpFileName='c:temp_adp.newandhot';

var

  rawHTM, buffer, DataBuf, ItemBuf : string;

  sTitle, sLink, sDesc, SWhenWhere : string;

  NewAndHotHTMFile : TextFile;

  iStart, iStop : integer;

  stop: boolean;

begin

  if NOT Download_HTM(ADPNEWHOTURL,TmpFileName) then

  begin

    ShowMessage('Error in HTML file download');

    Exit;

  end;

 

    //read the HTML file

    AssignFile(NewAndHotHTMFile, TmpFileName);

    try

      Reset(NewAndHotHTMFile);

      while not EOF(NewAndHotHTMFile) do begin

        ReadLn(NewAndHotHTMFile, buffer);

        rawHTM := Concat(rawHTM, buffer);

      end;

 

      //START find the new and hot data on the page located between  <!--DCnt--> and </!--DCnt-->

      iStart := Pos('<!--DCnt-->',rawHTM) + Length('<!--DCnt-->');

      iStop := Pos('<!--/DCnt-->',rawHTM);

      DataBuf := Copy(rawHTM, iStart, iStop-iStart);

      if DataBuf='' then

      begin

        with ListView1.Items.Add do

        begin

          Caption:= 'Format error';

          SubItems.Add(ADPNEWHOTURL);

          SubItems.Add('The HTML file with the news is not formated properly!');

          SubItems.Add('in ' + TmpFileName);

        end;

        Exit;

      end;

      //STOP find the new and hot data on the page located between  <!--DCnt--> and </!--DCnt-->

 

      //start remove any script inside the htm page

      stop:=False;

      repeat

        iStart := Pos('<script>',DataBuf) ;

        if iStart <> 0 then

        begin

          iStop := Pos('</script>', DataBuf) + Length('</script>');

          DataBuf := Copy(DataBuf, 0, iStart - 1) + Copy(DataBuf, iStop, MaxInt);

        end

        else

          stop:=True;

      until stop;

      //stop remove any script inside the htm page

 

      ListView1.Clear;

 

      //start grab one item at a time (example):

      (*

      <p>

      <a href="/library/bluc/ucvcl.htm"><b>FREE CODE VCL: stMasterComboBox</b></a><br>

      <i>06/10 in <a href="/library/bluc/ucvcl.htm">FREE VCL</a>.</i> stMasterComboBox is a combo box component that helps you to create master-detail forms supplying navigation with a combo box.

      </p>

      *)

      stop:=False;

      repeat

        iStart := Pos('<p>',DataBuf) + Length('<p>') ;

        if (iStart <> 0) AND (DataBuf <> '') then

        begin

          //find one item

          iStop := Pos('</p>', DataBuf);

          ItemBuf := Copy(DataBuf, iStart, iStop - iStart);

 

          //remove that one

          Delete(DataBuf, 1, -1 + iStop + Length('</p>'));

 

          //find the link

          iStart:=Pos('<a href="',ItemBuf) + Length('<a href="');

          iStop:=Pos('">',ItemBuf);

          sLink:= 'http://delphi.about.com' +  Copy(ItemBuf, iStart, iStop-iStart);

 

          //find the title

          iStart:=Pos('<b>',ItemBuf) + Length('<b>');

          iStop:=Pos('</b>',ItemBuf);

          sTitle:= Copy(ItemBuf, iStart, iStop-iStart);

 

          //date and location (When/Where)

          iStart:=Pos('<i>',ItemBuf) + Length('<i>');

          iStop:=Pos('</i>',ItemBuf);

          SWhenWhere := Copy(ItemBuf, iStart, iStop-iStart);

          iStart:=Pos('<a href="',SWhenWhere);

          iStop:=Pos('">',SWhenWhere);

          Delete(SWhenWhere, iStart, iStop - iStart + Length('">'));

          SWhenWhere := StringReplace(SWhenWhere,'</a>','',[]);

 

          //find the description

          sDesc:=Copy(ItemBuf,Pos('</i>',ItemBuf) + Length('</i>'),MaxInt);

 

          //add to list view

          with ListView1.Items.Add do

          begin

            Caption:= sTitle;

            SubItems.Add(sLink);

            SubItems.Add(sDesc);

            SubItems.Add(sWhenWhere);

          end;

        end

        else

          stop:=True;

      until stop;

    //Stop grab one item at a time:

    finally

      CloseFile(NewAndHotHTMFile);

    end;

 

    //delete the temp file

    try

      DeleteFile(TmpFileName)

    except

    end;

 

end;

 

end.

 

Project1.PAS

 

program Project1;

 

uses

  Forms,

  Unit1 in 'Unit1.pas' {Form1};

 

{$R *.res}

 

begin

  Application.Initialize;

  Application.CreateForm(TForm1, Form1);

  Application.Run;

end.

 

 

{

********************************************

Zarko Gajic

About.com Guide to Delphi Programming

http://delphi.about.com

email: delphi.guide@about.com

free newsletter: http://delphi.about.com/library/blnewsletter.htm

forum: http://forums.about.com/ab-delphi/start/

********************************************

}

 

Delphi - .....................................

 

html veri çekme

const

  ADPNEWHOTURL = 'http://www.bodrumonline.com/haber/haberonline.php';

  TmpFileName='c:temp_adp.newandhot';

var

  rawHTM, buffer, DataBuf, ItemBuf : string;

  sTitle, sLink, sDesc, SWhenWhere : string;

  NewAndHotHTMFile : TextFile;

  iStart, iStop : integer;

  stop: boolean;

begin

  if NOT Download_HTM(ADPNEWHOTURL,TmpFileName) then

  begin

    ShowMessage('Error in HTML file download');

    Exit;

  end;

  //read the HTML file

    AssignFile(NewAndHotHTMFile, TmpFileName);

    try

      Reset(NewAndHotHTMFile);

      while not EOF(NewAndHotHTMFile) do begin

        ReadLn(NewAndHotHTMFile, buffer);

        rawHTM := Concat(rawHTM, buffer);

      end;

      //START find the new and hot data on the page located between  <!--DCnt--> and </!--DCnt-->

      iStart := Pos('<!--DCnt-->',rawHTM) + Length('<!--DCnt-->');

      iStop := Pos('<!------------------------------------>',rawHTM);

      DataBuf := Copy(rawHTM, iStart, iStop-iStart);

      if DataBuf='' then

      begin

        with ListView1.Items.Add do

        begin

          Caption:= 'Format error';

          SubItems.Add(ADPNEWHOTURL);

          SubItems.Add('The HTML file with the news is not formated properly!');

          SubItems.Add('in ' + TmpFileName);

        end;

        Exit;

      end;

   //STOP find the new and hot data on the page located between  <!--DCnt--> and </!--DCnt-->

 

      //start remove any script inside the htm page

      stop:=False;

      repeat

        iStart := Pos('<script>',DataBuf) ;

        if iStart <> 0 then

        begin

          iStop := Pos('</script>', DataBuf) + Length('</script>');

          DataBuf := Copy(DataBuf, 0, iStart - 1) + Copy(DataBuf, iStop, MaxInt);

        end

        else

          stop:=True;

      until stop;

      //stop remove any script inside the htm page

 

      ListView1.Clear;

 

      //start grab one item at a time (example):

      (*

      <p>

      <a href="/library/bluc/ucvcl.htm"><b>FREE CODE VCL: stMasterComboBox</b></a><br>

      <i>06/10 in <a href="/library/bluc/ucvcl.htm">FREE VCL</a>.</i> stMasterComboBox is a combo box component that helps you to create master-detail forms supplying navigation with a combo box.

      </p>

      *)

      stop:=False;

      repeat

        iStart := Pos('<tr>',DataBuf) + Length('<tr>') ;

        if (iStart <> 0) AND (DataBuf <> '') then

        begin

          //find one item

          iStop := Pos('</tr>', DataBuf);

          ItemBuf := Copy(DataBuf, iStart, iStop - iStart);

 

          //remove that one

          Delete(DataBuf, 1, -1 + iStop + Length('</tr>'));

 

          //find the link

          iStart:=Pos('<a href="',ItemBuf) + Length('<a href="');

          iStop:=Pos('" target="_top">',ItemBuf);

          sLink:=Copy(ItemBuf, iStart, iStop-iStart);

 

          //find the title

          iStart:=Pos('" target="_top">',ItemBuf) + Length('" target="_top">');

          iStop:=Pos('</a>',ItemBuf);

          sTitle:= Copy(ItemBuf, iStart, iStop-iStart);

 

          //date and location (When/Where)

          iStart:=Pos('<i>',ItemBuf) + Length('<i>');

          iStop:=Pos('</i>',ItemBuf);

          SWhenWhere := Copy(ItemBuf, iStart, iStop-iStart);

          iStart:=Pos('<a href="',SWhenWhere);

          iStop:=Pos('">',SWhenWhere);

          Delete(SWhenWhere, iStart, iStop - iStart + Length('">'));

          SWhenWhere := StringReplace(SWhenWhere,'</a>','',[]);

 

          //find the description

          sDesc:=Copy(ItemBuf,Pos('</i>',ItemBuf) + Length('</i>'),MaxInt);

 

          //add to list view

          with ListView1.Items.Add do

          begin

            Caption:= sTitle;

            SubItems.Add(sLink);

 

 

          end;

        end

        else

          stop:=True;

      until stop;

    //Stop grab one item at a time:

    finally

      CloseFile(NewAndHotHTMFile);

    end;

 

    //delete the temp file

    try

      DeleteFile(TmpFileName)

    except

end;

 

Bu web sitesi ücretsiz olarak Bedava-Sitem.com ile oluşturulmuştur. Siz de kendi web sitenizi kurmak ister misiniz?
Ücretsiz kaydol