Archive for the ‘TurboC++’ Category

Access .MDB AutoIncrement Column value reset

utorok, október 25th, 2011
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("ALTER TABLE TableName ALTER COLUMN ColumnName AUTOINCREMENT(1,1);"); //(1,1)->The starting value will be 1, and it will increment by 1.
ADOQuery1->ExecSQL();

(Synapse THTTPSend->Document) TMemoryStream to AnsiString

streda, september 28th, 2011
THTTPSend *http=new(THTTPSend);
AnsiString s;
http->HTTPMethod("GET", "http://ide.as-to.eu/");
s.SetLength(http->Document->Size);
http->Document->Position = 0;
http->Document->Read(s.c_str(), s.Length());
Caption=s;

Integer to time

streda, september 28th, 2011
int sec=72;
ShowMessage(TimeToStr(TimeStampToDateTime(MSecsToTimeStamp(sec*1000+24*3600*1000)))); //show 0:01:12

Save file on UTF-8 encoding

streda, júl 27th, 2011
 FILE *file=fopen("file.txt","w");
 fwrite(UTF8Encode("ľščťžýáíé\n\nľčščk kkdjksd\n ščľšť").c_str(),UTF8Encode("ľščťžýáíé\n\nľčščk kkdjksd\n ščľšť").Length(),1,file);
 fclose(file);

Service Application-easy example

nedeľa, január 30th, 2011

V Turbo C++ si vytvoríme nový project:
Súbor->Nový->Ostatné->Service Application / (File->New->Other->Service Application)
Pridáme udalosť komponenty TService1:Object inspector ->Events->dvojklik na OnExecute čo nás prepne do editoru, kde sa nám vytvorila nová udalosť do ktorej pridáme:

while(!Terminated)
{
Beep();
Sleep(1000);
ServiceThread->ProcessRequests(false);
} 

Inštalácia služby:
Run->Parameters a do prostredného textboxu(Parameters:) dopíšeme hodnotu: /INSTALL
Odinštalácia služby:
Run->Parameters a do prostredného textboxu(Parameters:) dopíšeme hodnotu: /UNINSTALL
Spustenie služby:
Start->Control panel->Administrative Tools->Services->nájdeme a označíme názov našej služby a klikneme na Start (pred spustením je samozrejme službu nainštalovať cez parameter /INSTALL

[všetky úkony sa samozrejme dajú spraviť aj cez command line (cesta_k_službe /INSTALL /UNINSTALL /NAME=nazov a podobne)]

---Service_test.cpp---

//---------------------------------------------------------------------------
#include "Service_test.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TService1 *Service1;
//---------------------------------------------------------------------------
__fastcall TService1::TService1(TComponent* Owner)
	: TService(Owner)
{
}

TServiceController __fastcall TService1::GetServiceController(void)
{
	return (TServiceController) ServiceController;
}

void __stdcall ServiceController(unsigned CtrlCode)
{
	Service1->Controller(CtrlCode);
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceExecute(TService *Sender)
{

while(!Terminated)
{
Beep();
Sleep(1000);
ServiceThread->ProcessRequests(false);
}
}
//---------------------------------------------------------------------------

---Service_test.h---

//---------------------------------------------------------------------------
#ifndef Service_testH
#define Service_testH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <SvcMgr.hpp>
#include <vcl.h>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TService1 : public TService
{
__published:    // IDE-managed Components
	void __fastcall ServiceExecute(TService *Sender);
private:        // User declarations
public:         // User declarations
	__fastcall TService1(TComponent* Owner);
	TServiceController __fastcall GetServiceController(void);

	friend void __stdcall ServiceController(unsigned CtrlCode);
};
//---------------------------------------------------------------------------
extern PACKAGE TService1 *Service1;
//---------------------------------------------------------------------------
#endif