Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Arrays i ispis na Label

[es] :: Pascal / Delphi / Kylix :: Arrays i ispis na Label

[ Pregleda: 1757 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

reikonija
Faks<lll>
Visegrad

Član broj: 213271
Poruke: 121
*.teol.net.



+4 Profil

icon Arrays i ispis na Label29.09.2011. u 20:15 - pre 152 meseci
Znaci imam Edit box u koji korisnik unese npr. c:/program a ja trebam videti da li tu ima folder npr. 'Zvukovi , Skinovi , Fax'
Evo kako sam ja ta probao:
Code:

procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
MyArray : Array [0..3] of string ;
begin
myarray[0]:='Zvukovi';
myarray[1]:='Logovi';
myarray[2]:='Slike';
for i:=0 to 2 do
begin
if FolderPostoji(edit1.Text + myarray[i])=true then label1.caption:='postoji ' + myarray[i];
sleep(3);
end;
end;

kad probam bez for petlje np.
if FolderPostoji(edit1.Text + myarray[0])=true then label1.caption:='postoji ' + myarray[0];
program radi savrseno , al sa for nista , e sad da ja radim if nekoliko puta samo bih dzabe opteretio program...
Gde gresim....
 
Odgovor na temu

((BugA))
Igor Djordjevic
Bor, Srbija

Član broj: 29241
Poruke: 196
*.dynamic.isp.telekom.rs.

ICQ: 66516695
Sajt: www.MalamutKlub.com


+17 Profil

icon Re: Arrays i ispis na Label29.09.2011. u 20:57 - pre 152 meseci
Prvo pitanje - sta ce ti ovo Sleep(3)? =)

Ne znam sta podrazumevas pod tim da sa for petljom ne radi, ali ja kao problem ovde vidim da ti u svakom prolazu kroz petlju u istu labelu upisujes razlicitu vrednost. Na primer, u situaciji da sva tri foldera postoje, za i = 0 dobijas label1.caption := 'postoji Zvukovi', zatim za i = 1 dobijas label1.caption := 'postoji Logovi', i na kraju za i = 2 dobijas label1.caption := 'postoji Slike'. Ova poslednja vrednost ('postoji Slike') ce po izvrsenju procedure i ostati vidljiva korisniku (ono 'postoji Zvukovi' i 'postoji Logovi' neces ni stici da vidis).

Ili umesto:
Code:
if FolderPostoji(edit1.Text + myarray[i])=true then label1.caption:='postoji ' + myarray[i];
... stavi nesto ovako (da sve upises u jednu labelu):
Code:
if (FolderPostoji(edit1.Text + myarray[i])) then label1.caption := label1.caption + ' postoji ' + myarray[i];

... ili stavi tri labele (label1, label2, label3), pa uradi nesto ovako:
Code:
if (FolderPostoji(edit1.Text + myarray[i])) then TLabel(Form1.FindComponent('label'+IntToStr(i+1))).Caption := 'postoji ' + myarray[i];
... gde je Form1 ime tvoje forme.


[edit] Nisam odmah obratio paznju, sad sam ispravio, kad proveravas IF uslov ne moras da vrsis poredjenje sa TRUE, kao sto radis ovde:
Code:
if FolderPostoji(edit1.Text + myarray[i])=true then
... vec mozes direktno da koristis sam rezultat funkcije koji je bool(ean), tj. ovako:
Code:
if FolderPostoji(edit1.Text + myarray[i]) then


[Ovu poruku je menjao ((BugA)) dana 30.09.2011. u 11:38 GMT+1]
 
Odgovor na temu

salaczr

Član broj: 160654
Poruke: 103
*.dynamic.isp.telekom.rs.



+5 Profil

icon Re: Arrays i ispis na Label30.09.2011. u 09:44 - pre 152 meseci
Nema potrebe za komplikovanjem, Delphi nudi gomilu mogucnosti za ovakvu vrstu upotrebe.
Mozda bi trebao malo da pogledas winAPI. Evo ti jednog primera kako mozes da resis svoj problem uz primenu API-a
i Delphi-jevog FileListBox-a.

Code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ShellAPI, ShlObj, StdCtrls, FileCtrl;

type
  TForm1 = class(TForm)
    Button_1: TButton;
    Label_1: TLabel;
    FileListBox: TFileListBox;
    procedure Button_1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function BrowseDialog(const Title: string; const Flag: integer): string;
var
  lpItemID : PItemIDList;
  BrowseInfo : TBrowseInfo;
  DisplayName : array[0..MAX_PATH] of char;
  TempPath : array[0..MAX_PATH] of char;
begin
  Result:='';
  FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
  with BrowseInfo do begin
    hwndOwner := Application.Handle;
    pszDisplayName := @DisplayName;
    lpszTitle := PChar(Title);
    ulFlags := Flag;
  end;
  lpItemID := SHBrowseForFolder(BrowseInfo);
  if lpItemId <> nil then begin
    SHGetPathFromIDList(lpItemID, TempPath);
    Result := IncludeTrailingBackslash(TempPath);
    GlobalFreePtr(lpItemID);
  end;
end;

procedure TForm1.Button_1Click(Sender: TObject);
var
  dir, FolderName : string;
  i : Integer;
begin
 dir := BrowseDialog('Look in:', BIF_RETURNONLYFSDIRS);
 if dir = '' then
  Exit;

 label_1.Caption:=dir;

 FileListBox.FileType := [ftDirectory];
 FileListBox.Directory := dir;

 for i := 0 to FileListBox.Count - 1 do
   begin
     FolderName := Copy(FileListBox.Items[i], 2, Length(FileListBox.Items[i])-2);   // moras da uklonis "[" i "]" sa imena foldera
     if FolderName = 'Zvukovi' then  // radis sta hoces
     if FolderName = 'Skinovi' then  // radis sta hoces
     if FolderName = 'Slike' then  // radis sta hoces

     // proveris koje hoces ime foldera 
   end;
end;

end.


poz
 
Odgovor na temu

((BugA))
Igor Djordjevic
Bor, Srbija

Član broj: 29241
Poruke: 196
*.ptt.rs.

ICQ: 66516695
Sajt: www.MalamutKlub.com


+17 Profil

icon Re: Arrays i ispis na Label30.09.2011. u 10:35 - pre 152 meseci
salaczr, pa bre preko API-ja izgleda dosta komplikovanije nego sto je on napravio =))

Ne zalazim u to sta radi njegova funkcija FolderPostoji(), ali recimo sam Delphi ima funkciju DirectoryExists() kojoj se prinosi putanja foldera - npr. FolderExists('C:\Neki folder\Folder u njemu'), sto ce vratiti True ako "Folder u njemu" postoji na datoj lokaciji, osnosno vratiti False ako folder (putanja) ne postoji.

Tako, umesto:
Code:
if FolderPostoji(edit1.Text + myarray[i]) = true then
... moze da pise:
Code:
if FolderExists(edit1.Text + myarray[i]) then

Samo da obrati paznju da
Code:
Edit1.Text + myarray[i]
daje ispravnu putanju, da ne zaboravi neku kosu crtu.
 
Odgovor na temu

lan-mi
Lukic Milan
Zrenjanin

Član broj: 156359
Poruke: 140
*.dynamic.sbb.rs.

Sajt: https://lanmisoft.com


+1 Profil

icon Re: Arrays i ispis na Label30.09.2011. u 11:30 - pre 152 meseci
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
MyArray : Array [0..3] of string ;
begin
myarray[0]:='Zvukovi';
myarray[1]:='Logovi';
myarray[2]:='Slike';
for i:=0 to 2 do
begin
if FolderPostoji(edit1.Text + myarray)=true then begin
label1.caption:='postoji ' + myarray;
sleep(3);//izbaci
break; //probaj ovako ako ti vec funkcija radi
end;
end;
end;
Arduino Control Center
 
Odgovor na temu

reikonija
Faks<lll>
Visegrad

Član broj: 213271
Poruke: 121
*.teol.net.



+4 Profil

icon Re: Arrays i ispis na Label10.10.2011. u 20:06 - pre 152 meseci
Joj ljudi spasili ste pe probao sam sva rijesenja , izabrao sam jednu soluciju , izbacio sleep i boolean kod if-a.
A sto mrzim kad mi se dogode te male greskice...
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: Arrays i ispis na Label

[ Pregleda: 1757 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.