Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-08-2013
giulichajari giulichajari is offline
Miembro
 
Registrado: nov 2012
Posts: 306
Poder: 12
giulichajari Va por buen camino
Post Problema con funcion

Tengo una funcion asociada a un boton y los respectivos componentes pero me da un error en la tercera linea, dice "Declaration syntax error", es en la linea

Código Delphi [-]
unsigned int Drivetype = GetDriveType(Drive.c_str ());

Código Delphi [-]
AnsiString temp;
AnsiString Drive = AnsiString(DriveComboBox1->Drive) //EditDrive->Text;
unsigned int Drivetype = GetDriveType(Drive.c_str ());
switch (drivetype)
{
case 1 : temp = “No root directory”; return;
case DRIVE_REMOVABLE : temp = “Removable”; break;
case DRIVE_FIXED : temp = “Fixed”; break;
case DRIVE_REMOTE : temp = “Remote (network) drive”; break;
case DRIVE_CDROM : temp = “CD-ROM”; break;
case DRIVE_RAMDISK : temp = “RAM disk”; break;
default: temp = “Unknown”; return;
}
LabelDriveType->Caption = temp;
temp = “”;
DWORD VolumeSerialNumber = 0;
DWORD MaximumComponentLength = 0;
DWORD FileSystemFlags = 0;
char * volumeinfo = new char[255];
volumeinfo[0] = 0;
char* FileSystemNameBuffer = new char[255];
FileSystemNameBuffer[0] = 0;
GetVolumeInformation (Drive.c_str (), volumeinfo,
CHAPTER 14 Win32 API Functional Areas 530
255, &VolumeSerialNumber,
&MaximumComponentLength, &FileSystemFlags, 
?FileSystemNameBuffer,255);
if (strlen(volumeinfo) != 0)
EditVolumeInfo->Text = volumeinfo ;
else
EditVolumeInfo->Text = “- no label -”;
//Translate integer to chars for serial number
char string1[35];
char string2[35];
if (VolumeSerialNumber > 0)
{
unsigned int bottom = (LOWORD(VolumeSerialNumber));
unsigned int top = (HIWORD(VolumeSerialNumber));
sprintf(string1,”%04X”,top);
sprintf(string2,”%04X”,bottom);
LabelSerialNum->Caption = AnsiString(string1) + “-” + AnsiString(string2);
}
else
LabelSerialNum->Caption = “- unknown -”;
if (MaximumComponentLength > 0)
LabelMaxComponentLength->Caption = AnsiString(MaximumComponentLength) + “
?characters”;
else
LabelMaxComponentLength->Caption = “- unknown -”;
if (strlen(FileSystemNameBuffer) != 0)
LabelFileSystemNameBuffer->Caption = FileSystemNameBuffer;
else
LabelFileSystemNameBuffer->Caption = “- unknown -”;
LabelFileSystemFlags->Caption = “”; //AnsiString(FileSystemFlags);
if (FileSystemFlags & FS_CASE_IS_PRESERVED)
temp += AnsiString(“Filename case is preserved.\n”);
if (FileSystemFlags & FS_CASE_SENSITIVE)
temp += AnsiString(“Lookup is case-sensitive.\n”);
if (FileSystemFlags & FS_UNICODE_STORED_ON_DISK)
temp += AnsiString(“Supports Unicode in filenames.\n”);
if (FileSystemFlags & FS_PERSISTENT_ACLS)
temp += AnsiString(“Preserves and enforces ACLs.\n”);
if (FileSystemFlags & FS_FILE_COMPRESSION)
System Services 531
LISTING 14.6 Continued
temp += AnsiString(“Supports file-based compression.\n”);
if (FileSystemFlags & FS_VOL_IS_COMPRESSED)
temp += AnsiString(“Volume is compressed. (i.e., DoubleSpace).\n”);
LabelFileSystemFlags->Caption = temp;
DWORD spc = 0; //Sectors per cluster
DWORD bps = 0; //Bytes per cluster
DWORD cluster = 0; //clusters
DWORD freeclust = 0; //freeclusters
GetDiskFreeSpace (Drive.c_str (),&spc,&bps,&freeclust,&cluster) ;
unsigned long v1 = (unsigned long)cluster;
unsigned long v2 = (unsigned long) spc;
unsigned long v3 = (unsigned long) bps;
unsigned long volsize = (v1 * v2)/1024 * v3;
LabelVolumeSize->Caption = AnsiString(FormatSize(volsize));
unsigned long free_bytes = (freeclust * spc)/1024 * bps;
LabelFreeSpace->Caption = AnsiString(FormatSize(free_bytes));
if (volsize > 0)
LabelUsed->Caption = AnsiString(((volsize - free_bytes) * 100) / volsize) +
?“ %”;
else
LabelUsed->Caption = “n/a”;
}


Al parecer es la funcion Drive.c_str la que da el problema pero no logro darme cuenta que pasa.

Muchas gracias..
Saludos
Responder Con Cita
  #2  
Antiguo 06-08-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola giulichajari.

El error que mencionas se produce por la falta de un punto y coma:
Código:
...
  AnsiString Drive = AnsiString(DriveComboBox1->Drive);  // <- Aquí !!
  unsigned int DriveType = GetDriveType(Drive.c_str());
...
Pero no será el único... a golpe de vista vas a tener que revisar:
Código:
GetVolumeInformation (
  Drive.c_str (),
  volumeinfo,
  CHAPTER 14 Win32 API Functional Areas 530255, // Esto no es C++... 
  &VolumeSerialNumber,
  &MaximumComponentLength,
  &FileSystemFlags,
  ?FileSystemNameBuffer,  // "?" error
  255
);
Código:
...
  wsprintf(string1,"%04X",top);  // En lugar de sprintf  
  wsprintf(string2,"%04X",bottom); 
...
Código:
...
  if (FileSystemFlags & FS_FILE_COMPRESSION)
    System Services 531  LISTING 14.6 Continued // Esto tampoco es C++ 
...
Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 06-08-2013 a las 08:42:50.
Responder Con Cita
  #3  
Antiguo 06-08-2013
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.040
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Me ha recordado el (fin de la cita) de Rajoy.
Responder Con Cita
  #4  
Antiguo 06-08-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Cita:
Empezado por Casimiro Notevi Ver Mensaje
Me ha recordado el (fin de la cita) de Rajoy.
.

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #5  
Antiguo 07-08-2013
giulichajari giulichajari is offline
Miembro
 
Registrado: nov 2012
Posts: 306
Poder: 12
giulichajari Va por buen camino
Gracias

Gracias por responder...

Bueno ya me di cuenta que faltaba el punto y coma, y a decir verdad copie el codigo de un libro, por eso tiene el numero de pagina y un titulo que no corresponde, ademas el programa no esta identado.
Pero acabo de hacerle muchas correciones.
Una cosa : la funcion sprintf si la pude utilizar incluyendo la libreria

Código Delphi [-]
#include stdio.h

lo que no me acepta ahora es:
Código Delphi [-]
LabelVolumeSize->Caption = AnsiString(FormatSize(volsize));

porque no me toma "FormatSize", pero no se que libreria o .h incluir para que lo tome.

Saludos
Responder Con Cita
  #6  
Antiguo 08-08-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola giulichajari.

Cita:
Empezado por giulichajari Ver Mensaje
Una cosa : la funcion sprintf si la pude utilizar incluyendo la libreria

Código Delphi [-]
#include stdio.h
Lo que decis es correcto, no fuí claro en ese punto. Sólo te aconsejaba el uso de wsprintf para evitar la inclusión del .h
Cita:
lo que no me acepta ahora es:
Código Delphi [-]
LabelVolumeSize->Caption = AnsiString(FormatSize(volsize));

porque no me toma "FormatSize", pero no se que libreria o .h incluir para que lo tome.
Al menos yo no conozco ninguna función de Windows o Builder C++ con ese nombre, tal vez venga en una versión posterior de Builder C++ que la que dispongo. O también podría ser una función definida por el usuario en otra parte del código.

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #7  
Antiguo 10-08-2013
giulichajari giulichajari is offline
Miembro
 
Registrado: nov 2012
Posts: 306
Poder: 12
giulichajari Va por buen camino
De vuelta

Bueno vuelvo a publicar, porque no noto ningún efecto al apretar el boton al que tengo asociado el codigo, osea lo que entiendo es que los "labels" deberian cambiar, pero no sucede nada.

el codigo me quedo asi:

Código Delphi [-]
#include 
#include 
#include <string.h>
#include 

#pragma hdrstop
#pragma package(smart_init)
#pragma resource "*.dfm"
#include "Unit1.h"
#include 
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
        AnsiString temp;
        AnsiString Drive = AnsiString(DriveComboBox1->Drive); //EditDrive->Text;

        unsigned int drivetype = GetDriveType(Drive.c_str ());
switch (drivetype)
    {
        case 1 : temp = "No root directory"; return;
        case DRIVE_REMOVABLE : temp = "Removable"; break;
        case DRIVE_FIXED : temp = "Fixed"; break;
        case DRIVE_REMOTE : temp ="Remote (network) drive"; break;
        case DRIVE_CDROM : temp = "CD-ROM"; break;
        case DRIVE_RAMDISK : temp = "RAM disk"; break;
        default: temp = "Unknown"; return;
     }
        LabelDriveType->Caption = temp;
        temp = "";
        DWORD VolumeSerialNumber = 0;
        DWORD MaximumComponentLength = 0;
        DWORD FileSystemFlags = 0;
        char * volumeinfo = new char[255];
        volumeinfo[0] = 0;
        char* FileSystemNameBuffer = new char[255];
        FileSystemNameBuffer[0] = 0;
        GetVolumeInformation (Drive.c_str (), volumeinfo, 255,&VolumeSerialNumber,
        &MaximumComponentLength, &FileSystemFlags,
        FileSystemNameBuffer,255);
        if (strlen(volumeinfo) != 0)
                EditVolumeInfo->Text = volumeinfo ;
        else
                EditVolumeInfo->Text = "- no label -";
//Translate integer to chars for serial number
        char string1[35];
        char string2[35];
        if (VolumeSerialNumber > 0)
                {
                        unsigned int bottom = (LOWORD(VolumeSerialNumber));
                        unsigned int top = (HIWORD(VolumeSerialNumber));
                        sprintf(string1,"%04X",top);
                        sprintf(string2,"%04X",bottom);
                        LabelSerialNum->Caption = AnsiString(string1) + "-" + AnsiString(string2);
                }
        else
        {
                LabelSerialNum->Caption = "- unknown -";
        if (MaximumComponentLength > 0)
                LabelMaxComponentLength->Caption = AnsiString(MaximumComponentLength) + "characters";
        else
                LabelMaxComponentLength->Caption = "- unknown -";
        if (strlen(FileSystemNameBuffer) != 0)
                LabelFileSystemNameBuffer->Caption = FileSystemNameBuffer;
        else
                LabelFileSystemNameBuffer->Caption = "- unknown -";
                LabelFileSystemFlags->Caption = ""; //AnsiString(FileSystemFlags);
        if (FileSystemFlags & FS_CASE_IS_PRESERVED)
                temp += AnsiString("Filename case is preserved.\n");
        if (FileSystemFlags & FS_CASE_SENSITIVE)
                temp += AnsiString("Lookup is case-sensitive.\n");
        if (FileSystemFlags & FS_UNICODE_STORED_ON_DISK)
                temp += AnsiString("Supports Unicode in filenames.\n");
        if (FileSystemFlags & FS_PERSISTENT_ACLS)
                temp += AnsiString("Preserves and enforces ACLs.\n");
        if (FileSystemFlags & FS_FILE_COMPRESSION)
                temp += AnsiString("Supports file-based compression.\n");
        if (FileSystemFlags & FS_VOL_IS_COMPRESSED)
                temp += AnsiString("Volume is compressed. (i.e., DoubleSpace).\n");
        LabelFileSystemFlags->Caption = temp;
        DWORD spc = 0; //Sectors per cluster
        DWORD bps = 0; //Bytes per cluster
        DWORD cluster = 0; //clusters
        DWORD freeclust = 0; //freeclusters
        GetDiskFreeSpace (Drive.c_str (),&spc,&bps,&freeclust,&cluster) ;
        unsigned long v1 = (unsigned long)cluster;
        unsigned long v2 = (unsigned long) spc;
        unsigned long v3 = (unsigned long) bps;
        unsigned long volsize = (v1 * v2)/1024 * v3;
LabelVolumeSize->Caption = AnsiString(volsize);
        unsigned long free_bytes = (freeclust * spc)/1024 * bps;
LabelFreeSpace->Caption = AnsiString(free_bytes);
        if (volsize > 0)
                LabelUsed->Caption = AnsiString(((volsize - free_bytes) * 100) / volsize) +" %";
        else
                LabelUsed->Caption = "n/a";
}
};

Pero no se porque no pasa nada.

Muchas gracias
Saludos..
Responder Con Cita
  #8  
Antiguo 10-08-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Uno de los motivos probables que no veas ningún resultado se debe a estas líneas:
Código:
...
  unsigned int drivetype = GetDriveType(Drive.c_str ());
  switch (drivetype) {
    case 1 : temp = "No root directory"; return;  // <- aqui
    case DRIVE_REMOVABLE : temp = "Removable"; break;
    case DRIVE_FIXED : temp = "Fixed"; break;
    case DRIVE_REMOTE : temp ="Remote (network) drive"; break;
    case DRIVE_CDROM : temp = "CD-ROM"; break;
    case DRIVE_RAMDISK : temp = "RAM disk"; break;
    default: temp = "Unknown"; return;   // <- o aqui
   }
...
Si drivetype toma el valor 1 u otro no contemplado en los case del switch, saldrá de la función en ese punto y no ejecutará el codigo siguiente.

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #9  
Antiguo 11-08-2013
giulichajari giulichajari is offline
Miembro
 
Registrado: nov 2012
Posts: 306
Poder: 12
giulichajari Va por buen camino
Post Ok gracias

Cambie el primer return por un break y ahora funciona solo que me tira "0" y "unknown" y no me muestra la informacion, tendria que revisar el codigo, pero gracias por tu consejo ecfisa.
Responder Con Cita
  #10  
Antiguo 18-08-2013
giulichajari giulichajari is offline
Miembro
 
Registrado: nov 2012
Posts: 306
Poder: 12
giulichajari Va por buen camino
Nuevo codigo

Bueno he conseguido que me muestre una cosa por lo menos..

Los "DRIVE" son Defines...


Código Delphi [-]
#include 
#include 
#include <string.h>
#include 
#define DRIVE_UNKNOWN 0
#define DRIVE_NO_ROOT_DIR 1
#define DRIVE_REMOVABLE 2
#define DRIVE_FIXED 3
#define DRIVE_REMOTE 4
#define DRIVE_CDROM 5
#define DRIVE_RAMDISK 6
#pragma hdrstop
#pragma package(smart_init)
#pragma resource "*.dfm"
#include "Unit1.h"
#include 
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
        AnsiString temp;
        char Drive[256];
        AnsiString drive = DriveComboBox1->Drive; //EditDrive->Text;
        StrCopy(Drive,drive.c_str());
        StrCat(Drive,":\\");



        unsigned int DriveType = GetDriveType(Drive);
switch (DriveType)
    {
        case 1 : temp = "No root directory"; break;
        case 2 : temp = "Removable"; break;
        case 3 : temp = "Fixed"; break;
        case 4 : temp ="Remote (network) drive"; break;
        case 5 : temp = "CD-ROM"; break;
        case 6 : temp = "RAM disk"; break;
        default: temp = "Unknown"; return;
     }
        LabelDriveType->Caption = temp;
        temp = "";

El caso ahora es que el resto del codigo no funciona correctamente, porque me mustra 0 o desconocido.
Solo logro ver el tipo de volumen.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
problema con funcion!! MOCOSO07 HTML, Javascript y otros 0 12-01-2009 16:39:40
Problema con una funcion Alliance Varios 5 09-10-2008 02:38:32
Problema con declaración de función vivamotos C++ Builder 1 25-04-2008 10:35:56
Problema con la funcion mail JulioGO PHP 2 26-09-2005 11:24:15
problema al llamar una función sgarrido Varios 3 27-07-2004 01:14:33


La franja horaria es GMT +2. Ahora son las 23:34:25.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi