Jump to content

UniApplication.UniPlatform


chrisjohn82

Recommended Posts

Hi,

I'm trying to figure out how to use uniplatform. I want to know the platform the user i logging in from, web or mobile and then based on the platform i want to load the right login screen. I saw that somebody posted a thread about this but and i tried to use the code but did not get it to work.

 

Best Regards

Christian 

Link to comment
Share on other sites

Hello , review the example of mobile called Hybrid , which I understand can use the main form as login, from there flames the way according to the platform , I'm interested in the same topic , but it seems that should always be two sets the forms , one for mobile and one for desktop and have repeated the code to navigate or use the type of application registered in the main form that is automatically selected system , I would like to review your progress . There is a person who commented on a link to have uncoupled code to the form but lost if trace

Link to comment
Share on other sites

Hi,

 

If we basiccaly write how to detect platform with code it's look like this

type
  TUniPlatforms = set of TUniPlatform;
type
  TMainmForm = class(TUnimForm)
    procedure UnimFormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    uPlat: TUniPlatforms;
  end;
implementation

{$R *.dfm}

uses
  uniGUIVars, MainModule, uniGUIApplication;

function MainmForm: TMainmForm;
begin
  Result := TMainmForm(UniMainModule.GetFormInstance(TMainmForm));
end;

procedure TMainmForm.UnimFormCreate(Sender: TObject);
var
  platform:string;
begin
  uPlat := UniApplication.UniPlatform;

  if (upPhone in uPlat) then
     platform:= 'Phone'
  else if (upTablet in uPlat) then
    platform:= 'Tablet'
  else if (upDesktop in uPlat) then
    platform:= 'PC';
  else if (upiPad in uPlat) then
    platform:= 'iPad'
  else if (upiPod in uPlat) then
    platform:= 'iPod'
  else if (upiPhone in uPlat) then
    platform:= 'iPhone'
  else if (upAndroid in uPlat) then
    platform:= 'Android Mobile Device'
  else if (upDesktop in uPlat) then
    platform:= 'Desktop PC';
  else if (upAndroid in uPlat) then
    platform:= 'Android'
  else if (upiOS in uPlat) then
    platform:= 'iOS'
  else if (upDesktop in uPlat) then
    platform:= 'Desktop OS';
  else if (upDesktop in uPlat) then
    platform:= 'Desktop'
  else if (upMobile in uPlat) then
    platform:= 'Mobile';
end;

initialization
  RegisterAppFormClass(TMainmForm);

end.

In here first set type of TuniPlatform. after then when uniform created you can control which one is working. (this is the same code from Demos/Touch/Detect Platform with little changes)

 

But as @logisticasoft mentioned if you want mobile user's go to mobile login form, desktop user's go to desktop login form, you better make hybrid application.

 

And you can use ActionList for desktop and mobile button which has same code. (action list not working in mobile menus yet but)

Link to comment
Share on other sites

Hi, 

I tried the code, i have the following code in my project and i get an error message when i try it from my iphone > Undefined is not an object (evaluating 'new Ext.field.Text')  is there something i'm missing ?

 

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
   uPlat := UniApplication.UniPlatform;
   if (upDesktop in uPlat) then begin
      form1.Show();  // ​This is the desktop login form
   end else if (upMobile in uPlat) then begin
      form5.Show(); // This is the mobile login form 
   end;
end;
 
Best Regards 
Christian
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...