Fórum Como evitar erro na importado do listox se tiver ´ no doc. #347069

05/10/2007

0

Olá amigos, uma boa tarde.
Novamente estou aqui, agora com uma dúvida, com a ajuda dos amigos, o listbox que estou desenvolvendo esta quase 100¬, mas ainda acontece alguns bugs que estou vendo antes de levar para o cliente, pois nos colocamos no lugar do cliente, usando e abusando do software antes de levá-lo ao uso comercial.

O que acontece agora no meu listbox, na importação de todo o conteúdo de uma pasta, é que se tiver esse caracter ´, ele da erro na importação, então vamos com duas perguntas.

Como tirar esse caracter do documento ao abrí-lo no listbox, e segundo, como substituir, palavras acentuadas por palavras que não usem acentos, exemplo ã por a, ó por o e assim por diante.
Abaixo segue o código de como esta o geral da importação de documentos para o banco de dados.

Só lembrando, se algum documento por exemplo for assim test´dd.doc ele da erro na importação por causa do ´.

obrigado a todos


function RetiraExt(S: String): String;
Var
  Extensao: Integer;
begin
    Extensao := Pos(´.´, S);
    Delete(S, Extensao, 4);
    Result := S;
end;

function BrowseCallbackProc(hwnd: HWND; uMsg: UINT; lParam, lpData: LPARAM):
  Integer; stdcall;
var
  Path: array[0..MAX_PATH] of Char;
begin
  case uMsg of
    BFFM_INITIALIZED:
      begin
        SendMessage(hwnd, BFFM_SETSELECTION, 1, lpData);
        SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, lpData);
      end;
    BFFM_SELCHANGED:
      begin
        if SHGetPathFromIDList(Pointer(lParam), Path) then
          SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, Integer(@Path));
      end;
  end;
  Result := 0;
end;

function SelectDir(hOwner: THandle; const Caption, InitialDir: string;
  const Root: WideString; ShowStatus: Boolean; out Directory: string): Boolean;
var
  BrowseInfo: TBrowseInfo;
  Buffer: PChar;
  RootItemIDList,
    ItemIDList: PItemIDList;
  ShellMalloc: IMalloc;
  IDesktopFolder: IShellFolder;
  Eaten, Flags: LongWord; //LongInt;//
  Windows: Pointer;//^Integer;//
  Path: string;
begin
  Result := False;
  Directory := ´´;
  Path := InitialDir;
  if (Length(Path) > 0) and (Path[Length(Path)] = ´\´) then
    Delete(Path, Length(Path), 1);

  FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
  if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then
  begin
    Buffer := ShellMalloc.Alloc(MAX_PATH);
    try
      SHGetDesktopFolder(IDesktopFolder);
      IDesktopFolder.ParseDisplayName(hOwner, nil, PWideChar(Root), Eaten, RootItemIDList, Flags);
      with BrowseInfo do
      begin
        hwndOwner := hOwner;
        pidlRoot := RootItemIDList;
        pszDisplayName := Buffer;
        lpszTitle := PChar(Caption);
        ulFlags := BIF_RETURNONLYFSDIRS;
        if ShowStatus then
          ulFlags := ulFlags or BIF_STATUSTEXT;
        lParam := Integer(PChar(Path));
        lpfn := BrowseCallbackProc;
        iImage := 0;
      end;

      // Make the browser dialog modal.
      Windows := DisableTaskWindows(hOwner);
      try
        ItemIDList := ShBrowseForFolder(BrowseInfo);
      finally
        EnableTaskWindows(Windows);
      end;

      Result := ItemIDList <> nil;
      if Result then
      begin
        ShGetPathFromIDList(ItemIDList, Buffer);
        ShellMalloc.Free(ItemIDList);
        Directory := Buffer;
      end;
    finally
      ShellMalloc.Free(Buffer);
    end;
  end;
end;


procedure TFImportar.btnprocurarClick(Sender: TObject);
Var
   SearchFile: TSearchRec;
   FindResult: Integer;
   FilesDir, DirSelect: String;
Const
   DefaultExt = ´*.*´;
begin
     Listbox1.Clear;
     if SelectDir((Sender as TSpTBXButton).Parent.Handle, ´Procurar Diretório´, FilesDir, ´´, False, DirSelect) then
        FilesDir := DirSelect;
     if FilesDir = ´´ then
        Exit;
     if FilesDir[Length(FilesDir)] <> ´\´  then
        FilesDir := FilesDir + ´\´;
     if FilesDir <> ´´ then
        FindResult := FindFirst(FilesDir+DefaultExt, faArchive, SearchFile);
        try
           While FindResult = 0 do
           begin
                Application.ProcessMessages;
                ListBox1.Items.Add(UpperCase((RetiraExt(SearchFile.Name))));
                //ListBox1.Items.Add((RetiraExt(SearchFile.Name)));
                FindResult := FindNext(SearchFile);
           end;
        finally
              FindClose(SearchFile)
        end;
end;
:D


Junior-programador

Junior-programador

Responder

Posts

06/10/2007

Ruysalles

function busca_troca(Lstr_texto, Lstr_busca, Lstr_troca : string) : string;
var
i : integer;
begin
for i := 1 to length(Lstr_texto) do
begin
if Copy(Lstr_texto, i, 1) = Lstr_busca then
begin
Delete(Lstr_texto, i, 1);
Insert(Lstr_troca, Lstr_texto, i);
end;
end;
Result := Lstr_texto;
end;


Responder

Gostei + 0

06/10/2007

Ruysalles

function tira_acento(str: string): string;
var
i: integer;
begin
for i := 1 to Length ( str ) do
case str[i] of
´á´: str[i] := ´a´;
´é´: str[i] := ´e´;
´í´: str[i] := ´i´;
´ó´: str[i] := ´o´;
´ú´: str[i] := ´u´;
´à´: str[i] := ´a´;
´è´: str[i] := ´e´;
´ì´: str[i] := ´i´;
´ò´: str[i] := ´o´;
´ù´: str[i] := ´u´;
´â´: str[i] := ´a´;
´ê´: str[i] := ´e´;
´î´: str[i] := ´i´;
´ô´: str[i] := ´o´;
´û´: str[i] := ´u´;
´ä´: str[i] := ´a´;
´ë´: str[i] := ´e´;
´ï´: str[i] := ´i´;
´ö´: str[i] := ´o´;
´ü´: str[i] := ´u´;
´ã´: str[i] := ´a´;
´õ´: str[i] := ´o´;
´ñ´: str[i] := ´n´;
´ç´: str[i] := ´c´;
´Á´: str[i] := ´A´;
´É´: str[i] := ´E´;
´Í´: str[i] := ´I´;
´Ó´: str[i] := ´O´;
´Ú´: str[i] := ´U´;
´À´: str[i] := ´A´;
´È´: str[i] := ´E´;
´Ì´: str[i] := ´I´;
´Ò´: str[i] := ´O´;
´Ù´: str[i] := ´U´;
´Â´: str[i] := ´A´;
´Ê´: str[i] := ´E´;
´Î´: str[i] := ´I´;
´Ô´: str[i] := ´O´;
´Û´: str[i] := ´U´;
´Ä´: str[i] := ´A´;
´Ë´: str[i] := ´E´;
´Ï´: str[i] := ´I´;
´Ö´: str[i] := ´O´;
´Ü´: str[i] := ´U´;
´Ã´: str[i] := ´A´;
´Õ´: str[i] := ´O´;
´Ñ´: str[i] := ´N´;
´Ç´: str[i] := ´C´;
end;
Result := str;
end;


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar