Club Builder - Foros de discusión Club Builder
Foro de C++Builder en español
 
 FAQFAQ   BuscarBuscar   MiembrosMiembros   Grupos de UsuariosGrupos de Usuarios   RegistrarseRegistrarse 
 PerfilPerfil   Entra para ver tus mensajes privadosEntra para ver tus mensajes privados   EntrarEntrar 

de delphi a c++ builder

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: de delphi a c++ builder Responder citando

holas necesitaria su ayuda para pasar on objeto que me han pasado eque esta echo en pascal trate de pasarlo a c++ pero me saltan muchos errores aqui les va el codigo:
Código:

unit spectrum;

interface

uses
  Windows, Classes, Controls, Messages, Graphics;

type
  TSpectrumStyle = (ssSmooth, ssBlock);

  TMiniSpectrum = class(TGraphicControl)
  private
    FGradient: TBitmap;
    FBuffer: TBitmap;
    FScale: Single;
    FStyle: TSpectrumStyle;
    FValues: array [0..127] of Single;
    procedure SetStyle(const Value: TSpectrumStyle);
  protected
    procedure Paint; override;
    procedure Resize; override;
    procedure SetEnabled(Value: Boolean); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Draw;
  published
    property Align;
    property Scale: Single read FScale write FScale;
    property Style: TSpectrumStyle read FStyle write SetStyle;
    property OnClick;
  end;

implementation

uses
  fmod, fmodtypes;

{ TMiniSpectrum }

constructor TMiniSpectrum.Create(AOwner: TComponent);
var
  X, Y: Integer;
  R, G, B: Integer;
  C: TColor;
begin
  inherited;
  Color := clBlack;
  Width := 80;
  Height := 32;
  FScale := 4.0;
  FStyle := ssSmooth;
  Enabled := False;

  // Create draw buffer
  FBuffer := TBitmap.Create;
  FBuffer.PixelFormat := pf32bit;
  FBuffer.Width := Width;
  FBuffer.Height := Height;

  // Create gradient bitmap
  FGradient := TBitmap.Create;
  FGradient.PixelFormat := pf32bit;
  FGradient.Width := 4;
  FGradient.Height := 32;

  R := 255;
  G := 0;
  B := 0;

  for Y := 0 to 31 do
  begin
    if Y > 15 then
      Dec(R, 16)
    else
      Inc(G, 16);
    if R < 0 then
      R := 0;
    if G > 255 then
      G := 255;
    C := TColor(RGB(R, G, B));
    for X := 0 to 2 do
      FGradient.Canvas.Pixels[X, Y] := C;
    FGradient.Canvas.Pixels[3, Y] := TColor(0);
  end;
end;

destructor TMiniSpectrum.Destroy;
begin
  FGradient.Free;
  FBuffer.Free;
  inherited;
end;

type
  PSingleArray = ^TSingleArray;
  TSingleArray = array [0..0] of Single;

procedure TMiniSpectrum.Draw;
var
  Data: PSingleArray;
  PeakData: Single;
  W, X, Y: Integer;
  ARect: TRect;
begin
  FBuffer.Canvas.Brush.Color := Color;
  FBuffer.Canvas.FillRect(BoundsRect);

  if Enabled then
  begin
    Data := PSingleArray(FSOUND_DSP_GetSpectrum);
   //FSOUND_DSP_GetSpectrum es parte de una dll
    // Get the peak value of each block of four values
    for X := 0 to 127 do
    begin
      W := X * 4;
      FValues[X] := Data^[W];
      if Data^[W + 1] > FValues[X] then
        FValues[X] := Data^[W + 1];
      if Data^[W + 2] > FValues[X] then
        FValues[X] := Data^[W + 2];
      if Data^[W + 3] > FValues[X] then
        FValues[X] := Data^[W + 3];
      FValues[X] := FValues[X] * FScale;
      if FValues[X] > 1.0 then
        FValues[X] := 1.0;
    end;

    W := Width;
    if W > 128 then
      W := 128;

    case FStyle of
    ssSmooth:
      begin
        X := 0;
        while X < W do
        begin
          if FValues[X] > 0.0 then
          begin
            Y := Height - Trunc(FValues[X] * 1.0 * Height);
            FBuffer.Canvas.CopyRect(Rect(X, Y, X + 1, Height), FGradient.Canvas, Rect(0, Y, 1, FGradient.Height));
          end;
          Inc(X);
        end;
      end;
    ssBlock:
      begin
        // Sixteen values for every column
        PeakData := 0;
        X := 0;
        while X < W do
        begin
          if PeakData < FValues[X] then
            PeakData := FValues[X];
          if (X and 3 = 3) and (PeakData > 0.0) then
          begin
            Y := Height - Trunc(PeakData * 1.0 * Height);
            PeakData := 0;
            FBuffer.Canvas.CopyRect(Rect(X, Y, X + 4, Height), FGradient.Canvas, Rect(0, Y, 4, FGradient.Height));
          end;
          Inc(X);
        end;
      end;
    end;
  end
  else
  begin
    FBuffer.Canvas.Font.Color := clWhite;
    ARect := BoundsRect;
    DrawText(FBuffer.Canvas.Handle, 'Click for spectrum', -1, ARect, DT_WORDBREAK or DT_NOPREFIX or DT_VCENTER or DT_CENTER);
  end;

  // Copy the buffer to the control
  Canvas.Draw(0, 0, FBuffer);
end;

procedure TMiniSpectrum.Paint;
begin
  Draw;
end;

procedure TMiniSpectrum.Resize;
begin
  inherited;
  if Assigned(FBuffer) then
  begin
    FBuffer.Width := Width;
    FBuffer.Height := Height;
  end;
end;

procedure TMiniSpectrum.SetEnabled(Value: Boolean);
begin
  inherited;
  FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit, Value); //parte de una dll
end;

procedure TMiniSpectrum.SetStyle(const Value: TSpectrumStyle);
begin
  if FStyle <> Value then
  begin
    FStyle := Value;
    ZeroMemory(@FValues, SizeOf(FValues));
  end;
end;

end.


desde ya muchisimas gracias
_________________
Salu2
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mensaje    Asunto: Responder citando

holas

puedes usar el codigo en pascal en el c++ builder

solo agrega el .pas a tu proyecto y en el archivo de codigo que quieras usarlo finje que es una include en c++ por ejemplo


agrega ArchivoPascal.pas al proyecto y en el Unit1.h o cualquier archivo de codigo de c++ que quieras usarlo pon una include asi :

#include "ArchivoPascal.hpp"


y el compiler como que lo traduce el pascal a c++ al momento de compilarlo...

asi le hice una vez con el SuiSkin para que compilara una unit que trae para que funcione con el suiskin los raize componens

es una manera rara de hacerlo .. pero realmente practica...

espero esto te haya sido de ayuda


Saludos! Very Happy
_________________
Hermes David Montes de oca Segovia
dodongoxp@yahoo.com
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email Visitar sitio web del autor MSN Messenger
Mensaje    Asunto: ok Responder citando

usa la opcion de pascal e incluye en el proyecto tu archivo.....
Volver arriba
Ver perfil de usuario Enviar mensaje privado Visitar sitio web del autor MSN Messenger
Mensaje    Asunto: Responder citando

eso ya lo hice ya q trato de agotar posibiidades antes de preguntar por eso pedia ayuda para la traduccion del objeto creado yo algo lo hice pero me salta Orrores de linkeado..gracias
_________________
Salu2
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mensaje    Asunto: Responder citando

algo pude hacer ya q nose mucho de objetos y de pascal un poco

a ver si alguien me da una manititita(mujaja)
Código:

//---------------------------------------------------------------------------
//el cpp
#include <vcl.h>

#pragma hdrstop

#include "MiniSpectrum.h"
#include "mainr1.h"
#include "fmod.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TMiniSpectrum *)
{
        new TMiniSpectrum(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMiniSpectrum::TMiniSpectrum(TComponent* Owner)
        : TGraphicControl(Owner)
{
int X, Y;
int  R, G, B;
TColor C;

  Color = clBlack;
  Width = 80;
  Height = 32;
  FScale = 4.0;
  FStyle = ssSmooth;
  Enabled = False;

  //Graphics::TBitmap* bitmap(new Graphics::TBitmap());
  //TBitmap *FBuffer = new TBitmap;//->Create();
  Graphics::TBitmap* FBuffer(new Graphics::TBitmap());
  FBuffer->PixelFormat = pf32bit;
  FBuffer->Width = Width;
  FBuffer->Height = Height;


  //FGradient = TBitmap->Create;
  Graphics::TBitmap* FGradient(new Graphics::TBitmap());
  FGradient->PixelFormat = pf32bit;
  FGradient->Width = 4;
  FGradient->Height = 32;

  R = 255;
  G = 0;
  B = 0;

  for(Y=0;Y<31;Y++)
    {
    if (Y > 15)
      R-=16;
    else
      G+=16;

    if(R < 0)
      R = 0;

    if (G > 255)
      G = 255;

    C = TColor(RGB(R, G, B));
    for(X=0;X<2;X++)
        FGradient->Canvas->Pixels[X,Y]=C;//a qui me salta error
   
     FGradient->Canvas->Pixels[3,Y]=TColor(0);//a qui me salta error
 }

}
//---------------------------------------------------------------------------
namespace Minispectrum
{
      void __fastcall PACKAGE Register()
       {
                 TComponentClass classes[1] = {__classid(TMiniSpectrum)};
                 RegisterComponents("Standard", classes, 0);
        }
}
//---------------------------------------------------------------------------
void TMiniSpectrum::Draw(void)
{

  float *Data;
  float PeakData;
  int W, X, Y;
  TRect ARect;

  FBuffer->Canvas->Brush->Color = Color;
  FBuffer->Canvas->FillRect(BoundsRect);

  if (Enabled)
  {
    Data =FSOUND_DSP_GetSpectrum();


    for (X=0;X<127;X++)
    {
      W = X * 4;
      FValues[X] = Data[W];
      if (Data[W + 1] > FValues[X])
        FValues[X] = Data[W + 1];
      if (Data[W + 2] > FValues[X])
        FValues[X] = Data[W + 2];
      if (Data[W + 3] > FValues[X])
        FValues[X] = Data[W + 3];
      FValues[X] = FValues[X] * FScale;
      if (FValues[X] > 1.0)
        FValues[X] = 1.0;
    }

    W = Width;
    if (W > 128)
      W = 128;

    switch(FStyle)
    {
    case ssSmooth:
      {
        X = 0;
        while (X < W) do
        {
          if (FValues[X] > 0.0)
          {                 //*
            Y = Height - Trunc(FValues[X] * 1.0 * Height);//a qui me salta //error
            FBuffer->Canvas->CopyRect(Rect(X, Y, X + 1, Height), FGradient->Canvas, Rect(0, Y, 1, FGradient.Height));
          }
          X++;
        }
      }
    case ssBlock:
      {
        // Sixteen values for every column
        PeakData = 0;
        X= 0;
        while (X < W)
        {
          if (PeakData < FValues[X])
            PeakData = FValues[X];
          if ((X && 3 == 3) && (PeakData > 0.0) )
          {
            Y = Height - Trunc(PeakData * 1.0 * Height);//a qui me salta  //error
            PeakData = 0;
            FBuffer->Canvas->CopyRect(Rect(X, Y, X + 4, Height), FGradient->Canvas, Rect(0, Y, 4, FGradient->Height));
          }
          ++X;//Inc(X);
        }
      }
     }
    }
  }
  else
  {
    FBuffer->Canvas->Font->Color = clWhite;
    ARect = BoundsRect;
    DrawText(FBuffer->Canvas->Handle, "Click para ver spectrum", -1, ARect, DT_WORDBREAK || DT_NOPREFIX || DT_VCENTER || DT_CENTER);
  }

  // Copy the buffer to the control
  Canvas->Draw(0, 0, FBuffer);
}

void __fastcall TMiniSpectrum::Paint(void)
{
  Draw();
}

void __fastcall TMiniSpectrum::Resize(void)
{
  inherited;
  if (Assigned(FBuffer))
  {
    FBuffer->Width = Width;
    FBuffer->Height = Height;
  }
}

void __fastcall TMiniSpectrum::SetEnabled(bool Value)
{
  //inherited;
  FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit, Value)
}

void __fastcall TMiniSpectrum::SetStyle(TSpectrumStyle Value)
{
  if (FStyle!=Value)
  {
    FStyle = Value;
    ZeroMemory(@FValues, SizeOf(FValues));
  }
}


//---------------------------------------------------------------------------


y este el el h
Código:

//---------------------------------------------------------------------------

#ifndef MiniSpectrumH
#define MiniSpectrumH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
//---------------------------------------------------------------------------
enum TSpectrumStyle  { ssSmooth, ssBlock };//GraphicControl1 == TSpectrumStyle
class /*PACKAGE*/ TMiniSpectrum : public TGraphicControl
{
private:
        Graphics::TBitmap* FGradient;
   Graphics::TBitmap* FBuffer;
   float FScale;
   TSpectrumStyle FStyle;
   float FValues[128];
   virtual void __fastcall SetStyle(const TSpectrumStyle Value);
protected:
        void __fastcall Paint(void);
   DYNAMIC void __fastcall Resize(void);
   virtual void __fastcall SetEnabled(bool Value);
public:
   virtual void Draw(void);
        float *TSingleArray,*PSingleArray;
        __fastcall  TMiniSpectrum(Classes::TComponent* Owner);
          __fastcall ~TMiniSpectrum(void);

__published:
        __property Align  = {default=0};
   __property float Scale = {read=FScale, write=FScale};
   __property TSpectrumStyle Style = {read=FStyle, write=SetStyle, nodefault};
   __property OnClick ;
};
//---------------------------------------------------------------------------
#endif

_________________
Salu2
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mostrar mensajes de anteriores:   
Cambiar a:  
No puedes publicar temas nuevos en este foro
No puedes responder a temas en este foro
No puedes editar tus mensajes en este foro
No puedes borrar tus mensajes en este foro
No puedes votar en las encuestas de este foro


Hosting WordPress Indedmedia desde 3,99 €
© 2002–2026 Club Builder · Funciona con phpBB.